redux-saga-test-plan icon indicating copy to clipboard operation
redux-saga-test-plan copied to clipboard

Unit testing error: Assertion 1 failed: call effects do not match (Even though the expected and actual result are the same)

Open jean182 opened this issue 6 years ago • 8 comments

Hi I'm having this weird issue, that when I'm passing the call action in an unit test I'm receiving this error, test was working before, but I add to that saga a CancelToken for cancelling the request.

    Expected
    --------
    { '@@redux-saga/IO': true,
      combinator: false,
      type: 'CALL',
      payload: 
       { context: null,
         fn: [Function: getVisualizations],
         args: [ '1', { token: [Object], cancel: [Function: cancel] } ] } }

    Actual
    ------
    { '@@redux-saga/IO': true,
      combinator: false,
      type: 'CALL',
      payload: 
       { context: null,
         fn: [Function: getVisualizations],
         args: [ '1', { token: [Object], cancel: [Function: cancel] } ] } }

As you can see, I believe they're exactly the same outputs, but they don't match. This is the failing test:

    describe("Unit testing", () => {
      let saga = testSaga(getVisualizationSaga, action);
      const cancel = CancelToken.source();
      it("fetches visualizations", () => {
        saga
          .next()
          .call(getVisualizations, action.payload, cancel)

          .next()
          .put(fetchVisualizationsSucceed())

          .next()
          .isDone();
      });
    });
  });

jean182 avatar Sep 20 '19 21:09 jean182

Hi! I'm having the same issue.

Seems there code that generates the output only goes so deep, probably standard toString or something.

There might be differences hiding for you underneath the token or cancel keys.

klingenm avatar Nov 20 '19 13:11 klingenm

I've encountered same issue after injecting cancel token inside axios request. Have you found workaround since? I simply switched to expectSaga but it gives me pass for any code...

ilya-zinkevych avatar Aug 20 '20 16:08 ilya-zinkevych

I've encountered same issue after injecting cancel token inside axios request. Have you found workaround since? I simply switched to expectSaga but it gives me pass for any code...

Tbh I build a not so great service that already handled the cancelation token, so the request was pretty straight forward to test, maybe you can try testing the saga by yourself without the library and see if you notice any differences between the results.

jean182 avatar Aug 24 '20 19:08 jean182

@jean182 I did. The results differ only when I test with cancel token)

ilya-zinkevych avatar Aug 25 '20 06:08 ilya-zinkevych

Just spend some hours debugging this as well, it was our fault (a deeply nested undefined value) but if the error logs were expanded it would've been more obvious straightaway

Current log:

    Actual
    --------
    { '@@redux-saga/IO': true,
      combinator: false,
      type: 'CALL',
      payload: 
       { context: null,
         fn: [Function: getVisualizations],
         args: [ '1', { token: [Object] } ] } }

If log expands the nested object like so, it would've be easier to spot the error

    Actual
    --------
    { '@@redux-saga/IO': true,
      combinator: false,
      type: 'CALL',
      payload: 
       { context: null,
         fn: [Function: getVisualizations],
         args: [ '1', { token: { params: { id: undefined } } } ] } }

bodadotsh avatar Nov 26 '21 16:11 bodadotsh

@bodazhao how did you expand the log here? I've tried --expand and --debug and other things.

@TheSethness you can use the util library to do that.

In your test file you can write:

import util from 'util'
util.inspect.defaultOptions.depth = null

That will expand your objects in your test output.

kevinszuchet avatar Jan 31 '23 19:01 kevinszuchet