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

mockRejectedValue is not a sugar function to mockImplementation(() => Promise.reject(value)) #5839

Closed
rongduan-zhu opened this issue Mar 21, 2018 · 3 comments · Fixed by #5916

Comments

@rongduan-zhu
Copy link

rongduan-zhu commented Mar 21, 2018

  • you are using the latest version of Jest: Yes
  • try re-installing your node_modules folder: Yes
  • run Jest once with --no-cache to see if that fixes the problem you are experiencing. : Yes

Do you want to request a feature or report a bug?
bug

What is the current behavior?
In the documentation for mockRejectedValue, it states that it is a sugar function to mockImplementation(() => Promise.reject(value)), however as can be seen in the repl.it demo below, it is not. mockRejectedValue assumes that the rejection is handled immediately in the current event loop cycle, if it is not, it will cause the test to fail even though the rejection is handled in later cycles.

Repro
repl.it demo. Although the documentation say it's only available in 22.2.0+ and repl.it's jest version is 22.1.2, I have tried it locally with 22.4.2 and I am seeing the same issue.

What is the expected behavior?
Follow what the documentation states, "Simple sugar function for: jest.fn().mockImplementationOnce(() => Promise.reject(value));".

Please provide your exact Jest configuration

{
  "testRegex": ".*-test\\.js$",
  "testEnvironment": "node"
}

Run npx envinfo --preset jest in your project directory and paste the
results here

System:
    OS: Windows 10
    CPU: x64 Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz
  Binaries:
    Node: 9.4.0
    Yarn: 1.3.2
    npm: 5.6.0
@rongduan-zhu rongduan-zhu changed the title mockRejectedValue is not a sugar function to mockImplementation mockRejectedValue is not a sugar function to mockImplementation(() => Promise.reject(value)) Mar 21, 2018
@rickhanlonii
Copy link
Member

The docs are wrong here, this was changed in #5720 which hasn't been released yet

Fixed in the above PR, sorry for the confusion @rongduan-zhu!

@rongduan-zhu
Copy link
Author

Cool! Thank you @rickhanlonii

@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 12, 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