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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad interaction between using jest.mock returning mocks with implentation and the resetMocks configuration #7573

Closed
julienw opened this issue Jan 3, 2019 · 3 comments

Comments

@julienw
Copy link

julienw commented Jan 3, 2019

馃悰 Bug Report

I use something like this in my test file:

jest.mock('../path/to/module', () => ({
  exportedFunction: jest.fn(() => async() => {}), // obviously a thunk action
});

I also use the configuration variable resetMocks.
It looks like that the mocks seem to be reseted after the module factory has been called, while it should be reseted before so that any created mock inside the factory isn't reset.

As a result when we use the mocked functions inside a test, they return undefined instead of the expected return value, and the code fails.

Expected behavior

I expect that the return value defined in the module factory is kept even though I use resetMocks.

Especially I expect that the factory function is called again at each test. But maybe this is a wrong assertion...

Link to repl or repo (highly encouraged)

https://repl.it/repls/SecondhandSteelScripts

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Linux 4.18 Debian GNU/Linux 9 (stretch) 9 (stretch)
    CPU: (4) x64 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
  Binaries:
    Node: 9.11.1 - ~/.nvm/versions/node/v9.11.1/bin/node
    Yarn: 1.12.3 - ~/.yarn/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v9.11.1/bin/npm
  npmPackages:
    jest: ^23.5.0 => 23.6.0 
@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

github-actions bot commented May 2, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant