title: Redux - Jest: Testing functions that have void return
body: <p>New to Jest and Redux and I'm having trouble with testing functions that are dispatching to the store but don't yield a return value. I'm trying to follow the example from the <a href="http://redux.js.org/docs/recipes/WritingTests.html" rel="nofollow noreferrer">Redux website</a> does this</p>
  
  <pre><code>return store.dispatch(actions.fetchTodos()).then(() =&gt; {
        // return of async actions
        expect(store.getActions()).toEqual(expectedActions)
  })
  </code></pre>
  
  <p>however I have several "fetchtodos" functions that  don't return anything which causes the error <strong>TypeError</strong>: </p>
  
  <blockquote>
    <p><code>Cannot read property 'then' of undefined due to returning undefined</code></p>
  </blockquote>
  
  <p>I'm wondering what I can do to test that my mock store is correctly updating. Is there a way to dispatch the function, wait for it to finish and then compare the mock store with expected results?</p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p><strong>Edit: We're using typescript</strong></p>
  
  <p><strong>action from tsx</strong></p>
  
  <pre><code>export function selectTopic(topic: Topic | undefined): (dispatch: Redux.Dispatch&lt;TopicState&gt;) =&gt; void {
    return (dispatch: Redux.Dispatch&lt;TopicState&gt;): void =&gt; {
  
      dispatch({
        type: SELECT_Topic,
        payload: topic,
      });
  
      dispatch(reset(topic));
    };
  }
  </code></pre>
  
  <p><strong>test.tsx</strong></p>
  
  <pre><code>const middlewares = [thunk];
  const mockStore = configureMockStore(middlewares);
  
  describe('Select Topic action', () =&gt; {
    it('should create an action to select .', () =&gt; {
      const topic: Topic = mockdata.example[0];
      const expectedAction = {
        type: actions.SELECT_TOPIC,
        payload: topic,
      };
  
      const store = mockStore(mockdata.defaultState);
  
      return store.dispatch(actions.selectTopic(topic)).then(() =&gt; {
        expect(store.getState()).toEqual(expectedAction);
      });
    });
  });
  </code></pre>
  
  <p>The action is what I'm given to test(and there are many other functions similar to it. I'm getting that undefined error when running the test code, as the function isn't returning anything. </p>