redux-saga-test-plan
redux-saga-test-plan copied to clipboard
SagaTestError: call expectation unmet:
Hi, I am testing if a yield call has been executed. I receive this error which I probably misunderstand, but as far as I can tell the function is called with the same parameters in both the saga and the test file.
Does anyone know why the expectation is unmet?
Let me know if I need to post the saga/test suite.
` SagaTestError: call expectation unmet:
Expected
--------
{ '@@redux-saga/IO': true,
combinator: false,
type: 'CALL',
payload:
{ context: null,
fn:
{ [Function: mockConstructor]
_isMockFunction: true,
getMockImplementation: [Function],
mock: [Getter/Setter],
mockClear: [Function],
mockReset: [Function],
mockRestore: [Function],
mockReturnValueOnce: [Function],
mockResolvedValueOnce: [Function],
mockRejectedValueOnce: [Function],
mockReturnValue: [Function],
mockResolvedValue: [Function],
mockRejectedValue: [Function],
mockImplementationOnce: [Function],
mockImplementation: [Function],
mockReturnThis: [Function],
mockName: [Function],
getMockName: [Function] },
args: [ { user: [Object] } ] } }
Actual:
------
1. { '@@redux-saga/IO': true,
combinator: false,
type: 'CALL',
payload:
{ context: null,
fn:
{ [Function: mockConstructor]
_isMockFunction: true,
getMockImplementation: [Function],
mock: [Getter/Setter],
mockClear: [Function],
mockReset: [Function],
mockRestore: [Function],
mockReturnValueOnce: [Function],
mockResolvedValueOnce: [Function],
mockRejectedValueOnce: [Function],
mockReturnValue: [Function],
mockResolvedValue: [Function],
mockRejectedValue: [Function],
mockImplementationOnce: [Function],
mockImplementation: [Function],
mockReturnThis: [Function],
mockName: [Function],
getMockName: [Function] },
args: [ { user: [Object] } ] } }`
Having a similar case with jest mocking. not sure yet why they dont match
@maxammann do you mind to post your test case?
The reason for this is that redux-saga-test-plan probably checks for identify (===) when comparing the fn and arguments in a CALL effect comparision.
Now, jest is a bit crazy when it comes to mocking modules. It has a feature to reset the modules (jest.resetModules()). If you import a function from the same location before that and after that it will not the identical.
So after a call to jest.resetModules() you have to reimport EVERY module you use in the expect code. With out this call the test will fail.
It would be cool if the serializer could show that the arguments serialize to the same string but have a different identity.
As a workaround it is also possible to use the .like property which does not fail if it is not the same identity, e.g. expectSaga(foo, bar).call.like(baz, qux).run()
As a workaround it is also possible to use the
.likeproperty which does not fail if it is not the same identity, e.g.expectSaga(foo, bar).call.like(baz, qux).run()
Can you please give a more detailed example of using .like with expectSaga?
As a workaround it is also possible to use the
.likeproperty which does not fail if it is not the same identity, e.g.expectSaga(foo, bar).call.like(baz, qux).run()Can you please give a more detailed example of using
.likewith expectSaga?
Sure, see the docs here: https://github.com/jfairbank/redux-saga-test-plan/blob/7f78a0742f94c67a221a9a1370b65f65e38b66b6/docs/integration-testing/partial-matching.md