-
-
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-mock): Add example for ES6 modules #8550
docs(jest-mock): Add example for ES6 modules #8550
Conversation
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 [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
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
Compare
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.
Thanks! I just left a small nit, this LGTM!
Also, can you please update the versioned versions of this document?
docs/JestObjectAPI.md
Outdated
@@ -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: |
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.
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 🙂
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.
Actually had to research that :). Does something like that work?
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.
Yeah, I think so. Thanks!
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.
Pleasure!
@@ -0,0 +1,626 @@ | |||
--- | |||
id: version-24.6-jest-object |
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.
I don't think you have to add a new one - not sure though!
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.
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.
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.
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
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.
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
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 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.
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.
The example for using __esModule: true is also relevant for those versions, so it should be present.
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. |
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).