-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Documentation: guide for using jest.mock #8543
Comments
Hey @sargalias, thanks for your suggestion. This sounds a lot like the "Manual Mocks" guide, maybe it would make sense to extend that guide - I agree that more info on the signature of |
Hey @jeysal, that sounds like a good idea. I'll whip something up. |
Hi @jeysal, based on our conversation in #8544 I think it might be a better idea to proceed differently. As a recap, in #8544 it was suggested that it's fine for potentially missing information to be added to the API docs, but the guides should ideally only show best practices. If we consider manual mocks to be the preferred practice, then it may be better to add an example to the API docs for Please let me know if that sounds good. I'm happy to create a PR. |
The second |
Sounds good, thanks :). I've opened a small PR with just the addition to the |
* docs(JestObjectAPI jest-mock): Add example for ES6 modules Issue #8543 * chore(CHANGELOG): Update CHANGELOG * docs(JestObjectAPI jest-mock): Add explanation for __esModule: true Issue #8543 * docs(JestObjectAPI jest-mock): Update versioned_docs Issue #8543 * Revert "docs(JestObjectAPI jest-mock): Update versioned_docs" This reverts commit ba17c08. Updating the versioned_docs for version 24.6 is not necessary as we can update an earlier version and the changes will propagate to the new version. * docs(JestObjectAPI jest-mock): Update previous versioned_docs The example for using __esModule: true is also relevant for those versions, so it should be present.
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. |
🚀 Feature Proposal
A guide on basic mocking with jest using
jest.mock
. The guide would be on the sidebar after "Timer mocks".It would explain how to use
jest.mock
properly, what the different parameters do and provide examples for using them.Motivation
When I was a beginner I didn't understand how to use
jest.mock
at all, particularly the second parameter ofjest.mock
. This was even more fiddly because I use ES6 modules, giving the default export another "gotcha" when used in tests.As this is quite an essential feature for unit testing I think a guide will be beneficial to many users.
Please let me know your thoughts. If it sounds good I can make a PR.
The text was updated successfully, but these errors were encountered: