title: How to test rxjs ajax call with jest?
body: <p>I have a container component where I'm fetching the data via <code>ajax</code> operator from <code>rxjs</code></p>
  
  <pre><code>const data = ajax(someUrl).pipe(map(r =&gt; r.response));
  </code></pre>
  
  <p>And in my componentDidMount I have </p>
  
  <pre><code>data.subscribe((data) =&gt; {
      this.setState({ data });
  });
  </code></pre>
  
  <p>// test.js</p>
  
  <pre><code>import React from 'react';
  import { mount } from 'enzyme';
  import { ajax } from 'rxjs/ajax'
  import App from '../src/App';
  
  describe('&lt;App /&gt;', () =&gt; {
    const wrap = mount(&lt;App /&gt;);
    const data = [{ 1: 'a' }];
    const mock = ajax('http://url.com').pipe(map(() =&gt; data));
    it('renders', () =&gt; {
      console.log(mock.subscribe(x =&gt; x));
      expect(wrap.find(App).exists()).toBe(true);
    });
  });
  </code></pre>
  
  <p>How do I go about mocking the response so that when I run the test it I can pass that data on to other components and check if they render?</p>
  
  <p>All the testing examples I've found have been redux-Observable ones which I'm not using.</p>
  
  <p>Thanks a lot!</p>