title: How to test api calls within redux-saga
body: <p>I have this saga effects that calls to an API and dispatched an action if it is successful:</p>
  <pre><code>export function* getThemEffect() {
    try {
      yield put(requestActoin());
      const data: AxiosResponse&lt;ServerResponseSchema&gt; = yield call(getStuff);
      yield put(successAction(data.data.data));
    } catch (err: any) {
      yield put(failureAction(err?.response?.data || null));
    }
  }
  </code></pre>
  <p>This is the helper function:</p>
  <pre><code>export function getStuff() {
    const config: AxiosRequestConfig = {
      method: &quot;GET&quot;,
      url: &quot;https://somewhere.com/api/get&quot;
    };
    return axios(config);
  }
  </code></pre>
  <p>The test suit for this saga looks like this:</p>
  <pre><code>import * as api from &quot;../api&quot;;
  
  const getStuffSpy = jest.spyOn(api, &quot;getStuff&quot;);
  
  describe(&quot;search saga&quot;, () =&gt; {
     let gen: Generator, response: any, getStuffMock: jest.Mock;
     beforeEach(() =&gt; {
        getStuffSpy.mockClear();
        gen = getThemEffect();
        getStuffMock = jest.fn();
        getStuffSpy.mockImplementation(getStuffMock);
      });
     describe(&quot;server success response&quot;, () =&gt; {
        beforeEach(() =&gt; {
          response = { data: { data: [&quot;1&quot;, &quot;2&quot;, &quot;3&quot;] } };
        });
        it(&quot;should create correct success flow&quot;, () =&gt; {
          expect(gen.next()).toEqual({
            value: put(requestAction()),
            done: false
          });
          expect(gen.next()).toEqual({
            value: call(api.getStuff),
            done: false
          });
          expect(getStuffMock).toHaveBeenCalled(); // &lt;=== this fails
          expect(gen.next(response)).toEqual({
            value: put(successAction([&quot;1&quot;, &quot;2&quot;, &quot;3&quot;])),
            done: false
          });
          expect(gen.next()).toEqual({
            value: undefined,
            done: true
          });
        });
      });
  }
  </code></pre>
  <p>However the test that expects the <code>getStuffMock</code> function to have been called fails. How can I fix this? I am using jest with testing-library</p>