Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SagaTestError: call expectation unmet: #289

Open
WillyRamirez opened this issue Jul 18, 2019 · 7 comments
Open

SagaTestError: call expectation unmet: #289

WillyRamirez opened this issue Jul 18, 2019 · 7 comments
Labels

Comments

@WillyRamirez
Copy link

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] } ] } }`
@maxammann
Copy link

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

@jp928
Copy link
Collaborator

jp928 commented Sep 10, 2019

@maxammann do you mind to post your test case?

@jp928 jp928 added the critical label Sep 10, 2019
@maxammann
Copy link

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
Copy link

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

@steffenkleinle
Copy link

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

@mdenysov
Copy link

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?

@steffenkleinle
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants