Skip to content
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

Update documentation on automocking #5630

Merged
merged 12 commits into from
Feb 21, 2018
Merged

Conversation

czystyl
Copy link
Contributor

@czystyl czystyl commented Feb 21, 2018

Summary

Updated sections in documentation:

  • automock
  • genMockFromModule
  • enableAutomock and disabledAutomock

Added few example with tests related to changes that made in documentation.

Fixes #5290

Test plan

screen shot 2018-02-21 at 10 30 54

@facebook-github-bot
Copy link
Contributor

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!

@codecov-io
Copy link

codecov-io commented Feb 21, 2018

Codecov Report

Merging #5630 into master will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5630      +/-   ##
==========================================
- Coverage   60.94%   60.89%   -0.05%     
==========================================
  Files         215      215              
  Lines        7335     7319      -16     
  Branches        4        3       -1     
==========================================
- Hits         4470     4457      -13     
+ Misses       2864     2861       -3     
  Partials        1        1
Impacted Files Coverage Δ
...st-cli/src/plugins/update_snapshots_interactive.js 37.5% <0%> (-9.87%) ⬇️
packages/jest-cli/src/watch.js 72.46% <0%> (-0.27%) ⬇️
packages/jest-cli/src/plugins/update_snapshots.js 100% <0%> (ø) ⬆️
packages/jest-cli/src/plugins/test_name_pattern.js 100% <0%> (ø) ⬆️
packages/jest-cli/src/plugins/test_path_pattern.js 100% <0%> (ø) ⬆️
packages/jest-cli/src/base_watch_plugin.js
packages/jest-cli/src/watch_plugin.js 50% <0%> (ø)
packages/jest-runtime/src/index.js 73.55% <0%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ab04b7...91ea3b1. Read the comment docs.

});
```

If you are introducing Jest to a large organization with an existing codebase
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's a good recommendation now, as then switching to "automock": false will be painful. We should kill that paragraph imo.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with rolling back this guidance. You are right.

@@ -49,9 +49,43 @@ will be cleared and will never have the opportunity to execute in the future.

Disables automatic mocking in the module loader.

> See `automock` section of [configuration](Configuration.md) for more
Copy link
Collaborator

@thymikee thymikee Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link to the exact place, e.g. Configuration.md#automock-boolean?


```js
// __tests__/disableAutomocking.js
jest.disableAutomock();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be good to move this below import, babel-jest will hoist that.

@@ -75,6 +109,35 @@ Enables automatic mocking in the module loader.

Returns the `jest` object for chaining.

> See `automock` section of [configuration](Configuration.md) for more
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

direct link


```js
// __tests__/genMockFromModule.test.js
import utils from '../utils';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this, as it's not necessary and redefining it below will throw error.

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some notes inlined

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel it's good to go now. One last thing could be removing the // implementation comment, because it's not necessary.
Please remove it :)

@thymikee
Copy link
Collaborator

One more thing, a changelog entry! 😄

@thymikee thymikee changed the title Automocking dock Update documentation on automocking Feb 21, 2018
CHANGELOG.md Outdated
@@ -2,6 +2,8 @@

### Fixes

* `[docs]` Update automatic mocks documentation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add this under ### Chore & Maintenance section below Fixes

@czystyl
Copy link
Contributor Author

czystyl commented Feb 21, 2018

Ok done 👍

@sayo96
Copy link

sayo96 commented Apr 12, 2018

check this for a sample of manual and automatic mock
https://facebook.github.io/jest/docs/en/es6-class-mocks.html

@sayo96
Copy link

sayo96 commented Apr 12, 2018

using jest.mock( ' ' ) - creates a automatic mock whereas manual mocks are created by making mock functions in a seperate mock folder .Iam a newbie and its what i interpret upon first reading..

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic mocks/ automocking is not described in the docs
6 participants