redux-saga-test-plan
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)
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();
});
});
});
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.
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...
I've encountered same issue after injecting cancel token inside axios request. Have you found workaround since? I simply switched to
expectSagabut 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 I did. The results differ only when I test with cancel token)
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 } } } ] } }
@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.