-
-
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
docs(jest.doMock): Add information for using ES6 modules with doMock #8573
docs(jest.doMock): Add information for using ES6 modules with doMock #8573
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thanks!
docs/JestObjectAPI.md
Outdated
@@ -314,6 +314,46 @@ test('moduleName 2', () => { | |||
}); | |||
``` | |||
|
|||
Using `jest.doMock()` with ES6 modules requires additional steps: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it doesn't. Using jest.doMock
with ES6 import
s does. Please clarify this, because people may get wrong idea that they need to install some babel plugin to actually test a module.
This should clearly state something like: "use if you don't want to require
your ES6 modules"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, changed.
docs/JestObjectAPI.md
Outdated
foo: 'foo1', | ||
}; | ||
}); | ||
import('../moduleName').then(moduleName => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please either use async/await or return this promise from test – otherwise it's not gonna work properly. Same for the test below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes you're correct. Surprisingly these worked for me anyway (i.e. when changing the value in toEqual
the test failed), possibly some implementation detail of mocking and Babel.
Changed.
The steps outlined in jest.doMock for ES6 imports are only necessary if you don't want to use `require` in your tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Currently there is no information on how to use
jest.doMock()
with ES6 modules. Doing that requires a few additional steps that are non-intuitive.In this PR I expanded on the
jest.doMock()
API documentation to solve that problem.Test plan
The example code provided passes tests:
Please let me know if there is anything you'd like me to improve or if the PR isn't suitable.