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

mockImplementationOnce behaves differently than mockImplementation #8376

Closed
cdanielsen opened this issue Apr 24, 2019 · 2 comments · Fixed by #8398
Closed

mockImplementationOnce behaves differently than mockImplementation #8376

cdanielsen opened this issue Apr 24, 2019 · 2 comments · Fixed by #8398

Comments

@cdanielsen
Copy link

cdanielsen commented Apr 24, 2019

🐛 Bug Report

mockImplementationOnce does not override a default implementation set with a beforeEach like mockImplementation does

To Reproduce

See the repl link below

Expected behavior

I would expect the calls to mockImlementationOnce would have the same effect as mockImplementation in this scenario

Link to repl or repo (highly encouraged)

https://repl.it/@cdanielsen/Possible-jest-mockImplementationOnce-bug

Run npx envinfo --preset jest

Looks like repl.it is using an older version of jest (22.1.2) but I was able to repro this issue with the following config on my local machine and also via a run with npx jest@24.6

  System:
    OS: Linux 4.15 Ubuntu 18.04.2 LTS (Bionic Beaver)
    CPU: (3) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
  Binaries:
    Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
    Yarn: 1.12.3 - /usr/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0
@jeysal
Copy link
Contributor

jeysal commented Apr 24, 2019

Confirmed. Minimal repro:

  expect(
    jest
      .fn()
      .mockReturnValue(1)
      .mockImplementationOnce(() => 2)()
  ).toBe(2);

@github-actions
Copy link

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 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants