Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign updocs(jest-mock): Add example for ES6 modules #8550
Conversation
This comment has been minimized.
This comment has been minimized.
facebook-github-bot
commented
Jun 10, 2019
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
This comment has been minimized.
This comment has been minimized.
facebook-github-bot
commented
Jun 10, 2019
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
This comment has been minimized.
This comment has been minimized.
codecov-io
commented
Jun 10, 2019
•
Codecov Report
@@ Coverage Diff @@
## master #8550 +/- ##
=======================================
Coverage 60.57% 60.57%
=======================================
Files 269 269
Lines 11054 11054
Branches 2696 2696
=======================================
Hits 6696 6696
Misses 3772 3772
Partials 586 586 Continue to review full report at Codecov.
|
12ad487
to
29b3928
Thanks! I just left a small nit, this LGTM! Also, can you please update the versioned versions of this document? |
@@ -240,6 +240,23 @@ const moduleName = require('../moduleName'); | |||
moduleName(); // Will return '42'; | |||
``` | |||
|
|||
When using the `factory` parameter for an ES6 module with a default export, the `__esModule: true` property needs to be specified: |
This comment has been minimized.
This comment has been minimized.
SimenB
Jun 10, 2019
Collaborator
Can you add something about how both Babel's and TypeScript's module transform looks for this property? Without that context, it might look really weird, I think
This comment has been minimized.
This comment has been minimized.
sargalias
Jun 11, 2019
Author
Contributor
Actually had to research that :). Does something like that work?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -0,0 +1,626 @@ | |||
--- | |||
id: version-24.6-jest-object |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
sargalias
Jun 11, 2019
Author
Contributor
I wasn't sure either, but the other files in versioned_docs
do so I added it just in case :). I'm happy to change it if it's not ideal.
This comment has been minimized.
This comment has been minimized.
SimenB
Jun 11, 2019
Collaborator
Every PR is deployed, so you can remove this and check the deployed site on netlify
https://deploy-preview-8550--jest-preview.netlify.com/
If the versioned doc is incorrect, you can re-add this
This comment has been minimized.
This comment has been minimized.
thymikee
Jun 12, 2019
Collaborator
Looks like what you need to do is edit 22.x, 23.x and 24.0 versions of JestObjectAPI, separate 24.6 is not necessary
This comment has been minimized.
This comment has been minimized.
sargalias
Jun 12, 2019
Author
Contributor
Ah that was a great idea. Editing the previous versions added the example there too which is still relevant for those versions.
I also removed the file JestObjectAPI
from the versioned_docs for 24.6, as it's not needed anymore like you mentioned.
I tested locally (with yarn start
) and the changes are appearing for all versions.
* docs(JestObjectAPI jest-mock): Add example for ES6 modules Issue facebook#8543 * chore(CHANGELOG): Update CHANGELOG * docs(JestObjectAPI jest-mock): Add explanation for __esModule: true Issue facebook#8543 * docs(JestObjectAPI jest-mock): Update versioned_docs Issue facebook#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.
sargalias commentedJun 10, 2019
Issue #8543
Summary
Add an example on the
jest.mock
API docs for using thefactory
parameter for ES6 modules with default exports.Motivation
I haven't found information on how to do this in the Jest documentation. I believe this information should be available.
The issue is that compared to mocking out CommonJS modules, ES6 modules require the
esModule: true
property to be present.Test plan
This is purely a documentation change, so I have not touched the tests for the functional code in Jest.
Other
A similar test to the example code passes tests.
If I'm missing anything please let me know and I will fix it. In particular I wasn't sure what to do with the docs / versioned docs. Currently I have just edited the docs/JestObjectAPI.md file).