title: How to test Redux-Saga when catch error with jest
body: <p>everyone. I test saga with jest framework. I can test my saga in normal situation. But I want to test the code in catch(), so I have to mock a error to trigger catch. I find some solution in redux-saga offical document and other stackoverflow answer. But I still have a problem.</p>
  
  <p>when I use throw() in saga.test.js like the sample below, it will show "Error [object Object] thrown". So it can't really pass this test. I didn't see anyone ask same question. Could anyone help me? Thanks a lot.</p>
  
  <p>Error result screen:</p>
  
  <p><a href="https://i.stack.imgur.com/gbr5f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gbr5f.png" alt="img1"></a></p>
  
  <p>api.js</p>
  
  <pre><code>const api = {
    fetchProductAPI() {
      return 'iphone';
    },
  };
  export default api;
  </code></pre>
  
  <p>saga.js</p>
  
  <pre><code>import { call, put } from 'redux-saga/effects';
  import api from './api';
  
  export default function* fetchProduct() {
    try {
      yield call(api.fetchProductAPI);
      yield put({ type: 'PRODUCTS_RECEIVED', product: 'iphone' });
    } catch (error) {
      yield put({ type: 'PRODUCTS_REQUEST_FAILED', error });
    }
  }
  </code></pre>
  
  <p>saga.test.js</p>
  
  <pre><code>import { put, call } from 'redux-saga/effects';
  import fetchProduct from './saga';
  import api from './api';
  
  describe('fetchProduct()', () =&gt; {
    it('try', () =&gt; {
      const gen = fetchProduct();
      expect(gen.next().value).toEqual(call(api.fetchProductAPI));
      expect(gen.next().value).toEqual(put({ type: 'PRODUCTS_RECEIVED', product: 'iphone' }));
    });
    it('catch', () =&gt; {
      const error = 'product not found';
      const gen = fetchProduct();
      expect(
        gen.throw({
          error: 'product not found',
        }).value
      ).toEqual(put({ type: 'PRODUCTS_REQUEST_FAILED', error }));
    });
  });
  </code></pre>
  
  <p>The related solutions answer I found below:</p>
  
  <p><a href="https://github.com/redux-saga/redux-saga/blob/master/docs/basics/ErrorHandling.md" rel="nofollow noreferrer">Redux-Saga Error Handling</a></p>
  
  <p><a href="https://stackoverflow.com/questions/35654334/how-to-test-api-request-failures-with-redux-saga">How to test API request failures with Redux Saga?</a></p>