docs(jest.doMock): Add information for using ES6 modules with doMock#8573
Conversation
| }); | ||
| ``` | ||
|
|
||
| Using `jest.doMock()` with ES6 modules requires additional steps: |
There was a problem hiding this comment.
No it doesn't. Using jest.doMock with ES6 imports 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.
Good point, changed.
| foo: 'foo1', | ||
| }; | ||
| }); | ||
| import('../moduleName').then(moduleName => { |
There was a problem hiding this comment.
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.
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.
|
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.