title: Redux-actions Jest testing
body: <p>I use 'redux-actions' and have async action creator in Redux
  I try to write unit tests, but get an error:</p>
  <blockquote>
  <p>Timeout - Async callback was not invoked within the 100000 ms timeout specified by jest.setTimeout.</p>
  </blockquote>
  <p>Probably this is due to the call of the timer inside my action.
  How can I fix this error?</p>
  <p><code>actions.js</code></p>
  <pre><code>import axios from 'axios';
  import { createAction } from 'redux-actions';
  
  export const loadingNewsRequest = createAction('LOADING_NEWS_REQUEST');
  export const loadingNewsSuccess = createAction('LOADING_NEWS_SUCCESS');
  export const loadingNewsFailure = createAction('LOADING_NEWS_FAILURE');
  
  const path = 'http://127.0.0.1:7000';
  const timeout = 5000;
  const loadingTimeout = 60000;
  
  export const loadNews = () =&gt; async (dispatch) =&gt; {
    dispatch(loadingNewsRequest());
    try {
      const response = await axios.get(`${path}/news`, { timeout });
      const timer = setTimeout(() =&gt; loadNews()(dispatch), loadingTimeout);
      dispatch(loadingNewsSuccess({ allNews: response.data, timer }));
    } catch (err) {
      const timer = setTimeout(() =&gt; loadNews()(dispatch), loadingTimeout);
      dispatch(loadingNewsFailure({ err: err.message, timer }));
    }
  };
  </code></pre>
  <p><code>actions.test.js</code></p>
  <pre><code>import axios from 'axios';
  import MockAdapter from 'axios-mock-adapter';
  import configureStore from 'redux-mock-store';
  import thunk from 'redux-thunk';
  import * as actions from './index';
  
  const middlewares = [thunk];
  const mockStore = configureStore(middlewares);
  
  describe('loadNews', () =&gt; {
    const newsData = [ { x: 1}, { y: 2} ];
  
    it('returns data when sendMessage is called', async (done) =&gt; {
      const mock = new MockAdapter(axios);
      mock.onGet('http://127.0.0.1:7000/news').reply(200, newsData);
  
      jest.setTimeout(100000);
  
      const expectedActions = [
        actions.loadingNewsRequest(),
        actions.loadingNewsSuccess(
          {
            allNews: newsData,
            timer: 4,
          },
        ),
      ];
      const initialState = { allNews: [], timer: null };
      const store = mockStore(initialState);
  
      await store.dispatch(actions.loadNews());
      expect(store.getActions()).toEqual(expectedActions);
    });
  });
  </code></pre>