title: How can I test Observable.ajax (redux-observable)?
body: <p>I have been playing with rxjs and redux-observable for the last few days and have been struggle to find a way to a test for <em>Observable.ajax</em>. I have the following epic which create a request to <a href="https://jsonplaceholder.typicode.com/" rel="nofollow noreferrer">https://jsonplaceholder.typicode.com/</a>,</p>
  
  <pre><code>export function testApiEpic (action$) {
    return action$.ofType(REQUEST)
      .switchMap(action =&gt;
        Observable.ajax({ url, method })
          .map(data =&gt; successTestApi(data.response))
          .catch(error =&gt; failureTestApi(error))
          .takeUntil(action$.ofType(CLEAR))
      )
  }
  </code></pre>
  
  <p>where,</p>
  
  <pre><code>export const REQUEST = 'my-app/testApi/REQUEST'
  export const SUCCESS = 'my-app/testApi/SUCCESS'
  export const FAILURE = 'my-app/testApi/FAILURE'
  export const CLEAR = 'my-app/testApi/CLEAR'
  
  export function requestTestApi () {
    return { type: REQUEST }
  }
  export function successTestApi (response) {
    return { type: SUCCESS, response }
  }
  export function failureTestApi (error) {
    return { type: FAILURE, error }
  }
  export function clearTestApi () {
    return { type: CLEAR }
  }
  </code></pre>
  
  <p>The code works fine when runs in browser but not when testing with Jest.</p>
  
  <p>I have try,</p>
  
  <p>1) Create a test based on <a href="https://redux-observable.js.org/docs/recipes/WritingTests.html" rel="nofollow noreferrer">https://redux-observable.js.org/docs/recipes/WritingTests.html</a>. The store.getActions() returns only { type: REQUEST }.</p>
  
  <pre><code>const epicMiddleware = createEpicMiddleware(testApiEpic)
  const mockStore = configureMockStore([epicMiddleware])
  
  describe.only('fetchUserEpic', () =&gt; {
    let store
  
    beforeEach(() =&gt; {
      store = mockStore()
    })
  
    afterEach(() =&gt; {
      epicMiddleware.replaceEpic(testApiEpic)
    })
  
    it('returns a response, () =&gt; {
      store.dispatch({ type: REQUEST })
      expect(store.getActions()).toEqual([
        { type: REQUEST },
        { type: SUCCESS, response }
      ])
    })
  })
  </code></pre>
  
  <p>2) Create a test based on <a href="https://stackoverflow.com/questions/43188196/redux-observable-failed-jest-test-for-epic/43188527#43188527">Redux-observable: failed jest test for epic</a>. It returns with </p>
  
  <blockquote>
    <p>Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.</p>
  </blockquote>
  
  <pre><code>  it('returns a response', (done) =&gt; {
      const action$ = ActionsObservable.of({ type: REQUEST })
      const store = { getState: () =&gt; {} }
      testApiEpic(action$, store)
        .toArray()
        .subscribe(actions =&gt; {
          expect(actions).to.deep.equal([
            { type: SUCCESS, response }
          ])
          done()
        })
    })
  </code></pre>
  
  <p>Can someone point me out what is the correct way to test Observable.ajax ?</p>