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

New defaults for Jest. #1511

Merged
merged 1 commit into from Aug 30, 2016
Merged

New defaults for Jest. #1511

merged 1 commit into from Aug 30, 2016

Conversation

cpojer
Copy link
Member

@cpojer cpojer commented Aug 30, 2016

For Jest 15 we are going to ship with a ton of new defaults that should make the experience of using Jest better. With this, I also removed a bunch of outdated documentation from the website – however I feel like we should completely rewrite the documentation on the website and replace it with better, useful, step-by-step guides (cc @lacker).

This diff:

  • Disables automocking by default.
  • Uses real timers by default. Adds a timers: 'fake' | 'real' config option for global control.
  • Doesn't implicitly reset the module registry after every test. Adds jest.resetModules and a resetModules config option for better control.
  • Includes .test.js and .spec.js in the default testRegex.
  • Completely removes some deprecated configuration options and makes Jest throw with helpful error messages so that it will be easy for people to upgrade.
  • Adds a warning when jest.unmock is used to either enable automocking or remove the unmock calls. Similarly Jest now logs a warning if automocking isn't used but unmockedModulePathPatterns is specified.
  • Updates the docs to reflect the new defaults and removes some outdated pages.
  • Fixes two minor reporter bugs: the verbose reporter now prints the test header before any test results and top level test or it calls don't print a > right after the * bullet. (* works instead of * > works). I know this should have gone into separate diffs, but you know, sue me.
  • Removes obsolete testEnvData config option.

At Facebook we will continue to use automocking and fake timers for the foreseeable future and both features will continue to be part of Jest long term. Especially the auto mocking feature at this point is easy to maintain and the explicit auto-mocking using jest.mock is incredibly valuable. However, it makes a lot of sense for libraries and beginners to start with sane defaults. Automocking is valuable for big organizations that do not have a unit testing culture. I will elaborate this in the release blog post but wanted to give a few hints in here.

TODO: I'll add a few tests for the new errors tomorrow :)

cc @gaearon

@ghost ghost added the CLA Signed ✔️ label Aug 30, 2016
@suchipi
Copy link
Contributor

suchipi commented Aug 30, 2016

Excited for this release! Looking forward to new docs, too. I just picked up jest for a new personal project (via create-react-app#master) and it wasn't clear to me if I was supposed to require at top-level or within test cases (or in beforeEach), how jest.doMock will affect future test runs, whether a mock will persist outside the describe it was defined in, etc. I think a page giving a high-level overview of when jest will mock modules and how that works would help with that a ton.

@quantizor
Copy link
Contributor

This is really great stuff @cpojer :) completely gets rid of the few config changes I had in package.json ;)

@codecov-io
Copy link

codecov-io commented Aug 30, 2016

Current coverage is 63.09% (diff: 47.27%)

Merging #1511 into master will increase coverage by 0.24%

@@             master      #1511   diff @@
==========================================
  Files            97         97          
  Lines          3647       3647          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           2292       2301     +9   
+ Misses         1355       1346     -9   
  Partials          0          0          

Powered by Codecov. Last update 84516ce...9faefb3

@cpojer
Copy link
Member Author

cpojer commented Aug 30, 2016

Alright, should be good to go. Updated some older tests and added new ones.

@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 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants