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

SagaTestError: call expectation unmet:

Open WillyRamirez opened this issue 6 years ago • 7 comments

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] } ] } }`

WillyRamirez avatar Jul 18 '19 10:07 WillyRamirez

Having a similar case with jest mocking. not sure yet why they dont match

maxammann avatar Sep 10 '19 12:09 maxammann

@maxammann do you mind to post your test case?

jp928 avatar Sep 10 '19 13:09 jp928

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.

maxammann avatar Sep 10 '19 14:09 maxammann

It would be cool if the serializer could show that the arguments serialize to the same string but have a different identity.

maxammann avatar Sep 10 '19 14:09 maxammann

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()

steffenkleinle avatar Jun 08 '20 11:06 steffenkleinle

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()

Can you please give a more detailed example of using .like with expectSaga?

mdenysov avatar Jun 18 '20 07:06 mdenysov

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()

Can you please give a more detailed example of using .like with expectSaga?

Sure, see the docs here: https://github.com/jfairbank/redux-saga-test-plan/blob/7f78a0742f94c67a221a9a1370b65f65e38b66b6/docs/integration-testing/partial-matching.md

steffenkleinle avatar Jun 18 '20 11:06 steffenkleinle