diff --git a/.circleci/config.yml b/.circleci/config.yml
index e3cadb0b6788..f7051b683e40 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -26,7 +26,7 @@ jobs:
- restore-cache: *restore-cache
- run: yarn --no-progress
- save-cache: *save-cache
- - run: yarn lint --format junit -o reports/junit/js-lint-results.xml && yarn typecheck && yarn lint-es5-build --format junit -o reports/junit/js-es5-lint-results.xml && yarn lint:md:ci
+ - run: yarn lint --format junit -o reports/junit/js-lint-results.xml && yarn typecheck && yarn lint-es5-build --format junit -o reports/junit/js-es5-lint-results.xml && yarn lint:md:ci && yarn check-copyright-headers
- store_test_results:
path: reports/junit
diff --git a/.flowconfig b/.flowconfig
index 27a7723184e7..e4a6b93f5217 100644
--- a/.flowconfig
+++ b/.flowconfig
@@ -18,4 +18,4 @@ untyped-import
untyped-type-import
[version]
-^0.80.0
+^0.85.0
diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 000000000000..1019f4c475e3
--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1,3 @@
+fixtures/failing-jsons/
+packages/jest-config/src/__tests__/jest-preset.json
+packages/pretty-format/perf/world.geo.json
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5dcbe823063a..b4b9f192770a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
### Features
+- `[jest-validate]` Add support for comments in `package.json` using a `"//"` key [#7295](https://github.com/facebook/jest/pull/7295))
+- `[jest-config]` Add shorthand for watch plugins and runners ([#7213](https://github.com/facebook/jest/pull/7213))
- `[jest-config]` [**BREAKING**] Deprecate `setupTestFrameworkScriptFile` in favor of new `setupFilesAfterEnv` ([#7119](https://github.com/facebook/jest/pull/7119))
- `[jest-jasmine2/jest-circus/jest-cli]` Add test.todo ([#6996](https://github.com/facebook/jest/pull/6996))
- `[pretty-format]` Option to not escape strings in diff messages ([#5661](https://github.com/facebook/jest/pull/5661))
@@ -24,11 +26,18 @@
- `[jest-config]` Accept an array as as well as a string for `testRegex`([#7209]https://github.com/facebook/jest/pull/7209))
- `[babel-preset-jest]` [**BREAKING**] Export a function instead of an object for Babel 7 compatibility ([#7203](https://github.com/facebook/jest/pull/7203))
- `[expect]` Check constructor equality in .toStrictEqual() ([#7005](https://github.com/facebook/jest/pull/7005))
+- `[jest-util]` Add `jest.getTimerCount()` to get the count of scheduled fake timers ([#7285](https://github.com/facebook/jest/pull/7285))
+- `[jest-config]` Add `dependencyExtractor` option to use a custom module to extract dependencies from files ([#7313](https://github.com/facebook/jest/pull/7313), [#7349](https://github.com/facebook/jest/pull/7349), [#7350](https://github.com/facebook/jest/pull/7350))
+- `[jest-haste-map]` [**BREAKING**] Expose relative paths when getting the file iterator ([#7321](https://github.com/facebook/jest/pull/7321))
+- `[jest-haste-map]` Accept a `getCacheKey` method in `hasteImplModulePath` modules to reset the cache when the logic changes ([#7350](https://github.com/facebook/jest/pull/7350))
+- `[jest-config]` Add `haste.computeSha1` option to compute the sha-1 of the files in the haste map ([#7345](https://github.com/facebook/jest/pull/7345))
### Fixes
+- `[expect]` Standardize file naming in `expect` ([#7306](https://github.com/facebook/jest/pull/7306))
+- `[jest-each]` Add empty array validation check ([#7249](https://github.com/facebook/jest/pull/7249))
- `[jest-cli]` Interrupt tests if interactive watch plugin key is pressed ([#7222](https://github.com/facebook/jest/pull/7222))
-- `[jest-cli]` Fix coverage summary reporting ([#7058](https://github.com/facebook/jest/pull/7058))
+- `[jest-cli]` [**BREAKING**] Do not use `text-summary` coverage reporter by default if other reporters are configured ([#7058](https://github.com/facebook/jest/pull/7058))
- `[jest-each]` Add each array validation check ([#7033](https://github.com/facebook/jest/pull/7033))
- `[jest-haste-map]` Do not visit again files with the same sha-1 ([#6990](https://github.com/facebook/jest/pull/6990))
- `[jest-jasmine2]` Fix memory leak in Error objects hold by the framework ([#6965](https://github.com/facebook/jest/pull/6965))
@@ -54,9 +63,22 @@
- `[jest-changed-files]` Return correctly the changed files when using `lastCommit=true` on Mercurial repositories ([#7228](https://github.com/facebook/jest/pull/7228))
- `[babel-jest]` Cache includes babel environment variables ([#7239](https://github.com/facebook/jest/pull/7239))
- `[jest-config]` Use strings instead of `RegExp` instances in normalized configuration ([#7251](https://github.com/facebook/jest/pull/7251))
+- `[jest-circus]` Make sure to display real duration even if time is mocked ([#7264](https://github.com/facebook/jest/pull/7264))
+- `[expect]` Improves the failing message for `toStrictEqual` matcher. ([#7224](https://github.com/facebook/jest/pull/7224))
+- `[jest-mock]` [**BREAKING**] Fix bugs with mock/spy result tracking of recursive functions ([#6381](https://github.com/facebook/jest/pull/6381))
+- `[jest-resolve]` Fix not being able to resolve path to mapped file with custom platform ([#7312](https://github.com/facebook/jest/pull/7312))
+- `[jest-message-util]` Improve parsing of error messages for unusually formatted stack traces ([#7319](https://github.com/facebook/jest/pull/7319))
+- `[jest-runtime]` Ensure error message text is not lost on errors with code frames ([#7319](https://github.com/facebook/jest/pull/7319))
+- `[jest-haste-map]` Fix to resolve path that is start with words same as rootDir ([#7324](https://github.com/facebook/jest/pull/7324))
+- `[expect]` Fix toMatchObject matcher when used with `Object.create(null)` ([#7334](https://github.com/facebook/jest/pull/7334))
+- `[jest-haste-map]` [**BREAKING**] Recover files correctly after haste name collisions are fixed ([#7329](https://github.com/facebook/jest/pull/7329))
+- `[jest-haste-map]` Remove legacy condition for duplicate module detection ([#7333](https://github.com/facebook/jest/pull/7333))
+- `[jest-haste-map]` Fix `require` detection with trailing commas and ignore `import typeof` modules ([#7385](https://github.com/facebook/jest/pull/7385))
### Chore & Maintenance
+- `[jest-watcher]` Standardize filenames ([#7314](https://github.com/facebook/jest/pull/7314))
+- `[jest-circus]` Standardize file naming in `jest-circus` ([#7301](https://github.com/facebook/jest/pull/7301))
- `[docs]` Add synchronous test.each setup ([#7150](https://github.com/facebook/jest/pull/7150))
- `[docs]` Add `this.extend` to the Custom Matchers API reference ([#7130](https://github.com/facebook/jest/pull/7130))
- `[docs]` Fix default value for `coverageReporters` value in configuration docs ([#7126](https://github.com/facebook/jest/pull/7126))
@@ -81,6 +103,15 @@
- `[tests]` Free tests from the dependency on value of FORCE_COLOR ([#6585](https://github.com/facebook/jest/pull/6585/files))
- `[jest-diff]` Standardize filenames ([#7238](https://github.com/facebook/jest/pull/7238))
- `[*]` Add babel plugin to make sure Jest is unaffected by fake Promise implementations ([#7225](https://github.com/facebook/jest/pull/7225))
+- `[jest-haste-map]` Standardize filenames ([#7266](https://github.com/facebook/jest/pull/7266))
+- `[*]` [**BREAKING**] Require Node.js 6+ for all packages ([#7258](https://github.com/facebook/jest/pull/7258))
+- `[docs]` Add correct default value for `testUrl` config option ([#7277](https://github.com/facebook/jest/pull/7277))
+- `[jest-util]` [**BREAKING**] Remove long-deprecated globals for fake timers ([#7285](https://github.com/facebook/jest/pull/7285))
+- `[docs]` Remove duplicate code in `MockFunctions` ([#7297](https://github.com/facebook/jest/pull/7297))
+- `[jest-worker]` Standardize filenames ([#7316](https://github.com/facebook/jest/pull/7316))
+- `[pretty-format]` Standardize filenames ([#7316](https://github.com/facebook/jest/pull/7316))
+- `[*]` Add check for Facebook copyright headers on CI ([#7370](https://github.com/facebook/jest/pull/7370))
+- `[jest-haste-map]` Refactor `dependencyExtractor` and tests ([#7385](https://github.com/facebook/jest/pull/7385))
### Performance
@@ -172,9 +203,6 @@
### Fixes
- `[jest-haste-map]` Optimize watchman crawler by using `glob` on initial query ([#6689](https://github.com/facebook/jest/pull/6689))
-
-### Fixes
-
- `[pretty-format]` Fix formatting of invalid Date objects ([#6635](https://github.com/facebook/jest/pull/6635))
## 23.4.0
@@ -335,7 +363,7 @@
- `[jest-diff]` Support returning diff from oneline strings ([#6221](https://github.com/facebook/jest/pull/6221))
- `[expect]` Improve return matchers ([#6172](https://github.com/facebook/jest/pull/6172))
- `[jest-cli]` Overhaul watch plugin hooks names ([#6249](https://github.com/facebook/jest/pull/6249))
-- `[jest-mock]` Include tracked call results in serialized mock ([#6244](https://github.com/facebook/jest/pull/6244))
+- `[jest-mock]` [**BREAKING**] Include tracked call results in serialized mock ([#6244](https://github.com/facebook/jest/pull/6244))
### Fixes
diff --git a/README.md b/README.md
index 6b4a8478b16b..2101801f4e6a 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,7 @@
+
diff --git a/docs/Configuration.md b/docs/Configuration.md
index 55281c790207..8cc5493f7864 100644
--- a/docs/Configuration.md
+++ b/docs/Configuration.md
@@ -257,6 +257,16 @@ Jest will fail if:
- The `./src/api/very-important-module.js` file has less than 100% coverage.
- Every remaining file combined has less than 50% coverage (`global`).
+### `dependencyExtractor` [string]
+
+Default: `undefined`
+
+This option allows the use of a custom dependency extractor. It must be a node module that exports an object with an `extract` function expecting a string as the first argument for the code to analyze and Jest's dependency extractor as the second argument (in case you only want to extend it).
+
+The function should return an iterable (`Array`, `Set`, etc.) with the dependencies found in the code.
+
+That module can also contain a `getCacheKey` function to generate a cache key to determine if the logic has changed and any cached artifacts relying on it should be discarded.
+
### `errorOnDeprecated` [boolean]
Default: `false`
@@ -609,6 +619,8 @@ This option allows you to use a custom runner instead of Jest's default test run
- [`jest-runner-tsc`](https://github.com/azz/jest-runner-tsc)
- [`jest-runner-prettier`](https://github.com/keplersj/jest-runner-prettier)
+_Note: The `runner` property value can omit the `jest-runner-` prefix of the package name._
+
To write a test-runner, export a class with which accepts `globalConfig` in the constructor, and has a `runTests` method with the signature:
```ts
@@ -905,7 +917,7 @@ An example of such function can be found in our default [jasmine2 test runner pa
### `testURL` [string]
-Default: `about:blank`
+Default: `http://localhost`
This option sets the URL for the jsdom environment. It is reflected in properties such as `location.href`.
@@ -962,3 +974,37 @@ Default: `[]`
An array of RegExp patterns that are matched against all source file paths before re-running tests in watch mode. If the file path matches any of the patterns, when it is updated, it will not trigger a re-run of tests.
These patterns match against the full path. Use the `` string token to include the path to your project's root directory to prevent it from accidentally ignoring all of your files in different environments that may have different root directories. Example: `["/node_modules/"]`.
+
+### `watchPlugins` [array]
+
+Default: `[]`
+
+This option allows you to use a custom watch plugins. Read more about watch plugins [here](watch-plugins).
+
+Examples of watch plugins include:
+
+- [`jest-watch-master`](https://github.com/rickhanlonii/jest-watch-master)
+- [`jest-watch-select-projects`](https://github.com/rogeliog/jest-watch-select-projects)
+- [`jest-watch-suspend`](https://github.com/unional/jest-watch-suspend)
+- [`jest-watch-typeahead`](https://github.com/jest-community/jest-watch-typeahead)
+- [`jest-watch-yarn-workspaces`](https://github.com/cameronhunter/jest-watch-directories/tree/master/packages/jest-watch-yarn-workspaces)
+
+_Note: The values in the `watchPlugins` property value can omit the `jest-watch-` prefix of the package name._
+
+### `//` [string]
+
+No default
+
+This option allow comments in `package.json`. Include the comment text as the value of this key anywhere in `package.json`.
+
+Example:
+
+```json
+{
+ "name": "my-project",
+ "jest": {
+ "//": "Comment goes here",
+ "verbose": true
+ }
+}
+```
diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md
index 4f861066cab3..699de85fbc22 100644
--- a/docs/GettingStarted.md
+++ b/docs/GettingStarted.md
@@ -15,6 +15,8 @@ Or [`npm`](https://www.npmjs.com/):
npm install --save-dev jest
```
+Note: Jest documentation uses `yarn` commands, but `npm` will also work. You can compare `yarn` and `npm` commands in the [yarn docs, here](https://yarnpkg.com/en/docs/migrating-from-npm#toc-cli-commands-comparison).
+
Let's get started by writing a test for a hypothetical function that adds two numbers. First, create a `sum.js` file:
```javascript
@@ -44,7 +46,7 @@ Add the following section to your `package.json`:
}
```
-Finally, run `yarn test` and Jest will print this message:
+Finally, run `yarn test` or `npm run test` and Jest will print this message:
```bash
PASS ./sum.test.js
@@ -57,7 +59,7 @@ This test used `expect` and `toBe` to test that two values were exactly identica
## Running from command line
-You can run Jest directly from the CLI (if it's globally available in your `PATH`, e.g. by `yarn global add jest`) with a variety of useful options.
+You can run Jest directly from the CLI (if it's globally available in your `PATH`, e.g. by `yarn global add jest` or `npm install jest --global`) with a variety of useful options.
Here's how to run Jest on files matching `my-test`, using `config.json` as a configuration file and display a native OS notification after the run:
@@ -79,7 +81,7 @@ jest --init
### Using Babel
-To use [Babel](http://babeljs.io/), install the `babel-jest` and `@babel/core` packages:
+To use [Babel](http://babeljs.io/), install the `babel-jest` and `@babel/core` packages via `yarn`:
```bash
yarn add --dev babel-jest @babel/core
diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md
index 0442c12a34e6..7d42bb08235e 100644
--- a/docs/JestObjectAPI.md
+++ b/docs/JestObjectAPI.md
@@ -5,45 +5,7 @@ title: The Jest Object
The `jest` object is automatically in scope within every test file. The methods in the `jest` object help create mocks and let you control Jest's overall behavior.
-## Methods
-
-- [`jest.clearAllTimers()`](#jestclearalltimers)
-- [`jest.disableAutomock()`](#jestdisableautomock)
-- [`jest.enableAutomock()`](#jestenableautomock)
-- [`jest.fn(implementation)`](#jestfnimplementation)
-- [`jest.isMockFunction(fn)`](#jestismockfunctionfn)
-- [`jest.genMockFromModule(moduleName)`](#jestgenmockfrommodulemodulename)
-- [`jest.mock(moduleName, factory, options)`](#jestmockmodulename-factory-options)
-- [`jest.unmock(moduleName)`](#jestunmockmodulename)
-- [`jest.doMock(moduleName, factory, options)`](#jestdomockmodulename-factory-options)
-- [`jest.dontMock(moduleName)`](#jestdontmockmodulename)
-- [`jest.clearAllMocks()`](#jestclearallmocks)
-- [`jest.resetAllMocks()`](#jestresetallmocks)
-- [`jest.restoreAllMocks()`](#jestrestoreallmocks)
-- [`jest.resetModules()`](#jestresetmodules)
-- [`jest.retryTimes()`](#jestretrytimes)
-- [`jest.runAllTicks()`](#jestrunallticks)
-- [`jest.runAllTimers()`](#jestrunalltimers)
-- [`jest.advanceTimersByTime(msToRun)`](#jestadvancetimersbytimemstorun)
-- [`jest.runOnlyPendingTimers()`](#jestrunonlypendingtimers)
-- [`jest.requireActual()`](#jestrequireactual)
-- [`jest.requireMock()`](#jestrequiremock)
-- [`jest.setMock(moduleName, moduleExports)`](#jestsetmockmodulename-moduleexports)
-- [`jest.setTimeout(timeout)`](#jestsettimeouttimeout)
-- [`jest.useFakeTimers()`](#jestusefaketimers)
-- [`jest.useRealTimers()`](#jestuserealtimers)
-- [`jest.spyOn(object, methodName)`](#jestspyonobject-methodname)
-- [`jest.spyOn(object, methodName, accessType?)`](#jestspyonobject-methodname-accesstype)
-
----
-
-## Reference
-
-### `jest.clearAllTimers()`
-
-Removes any pending timers from the timer system.
-
-This means, if any timers have been scheduled (but have not yet executed), they will be cleared and will never have the opportunity to execute in the future.
+## Mock Modules
### `jest.disableAutomock()`
@@ -56,7 +18,9 @@ After this method is called, all `require()`s will return the real versions of e
Jest configuration:
```json
-"automock": true
+{
+ "automock": true
+}
```
Example:
@@ -126,24 +90,6 @@ test('original implementation', () => {
_Note: this method was previously called `autoMockOn`. When using `babel-jest`, calls to `enableAutomock` will automatically be hoisted to the top of the code block. Use `autoMockOn` if you want to explicitly avoid this behavior._
-### `jest.fn(implementation)`
-
-Returns a new, unused [mock function](MockFunctionAPI.md). Optionally takes a mock implementation.
-
-```js
-const mockFn = jest.fn();
-mockFn();
-expect(mockFn).toHaveBeenCalled();
-
-// With a mock implementation:
-const returnsTrue = jest.fn(() => true);
-console.log(returnsTrue()); // true;
-```
-
-### `jest.isMockFunction(fn)`
-
-Determines if the given function is a mocked function.
-
### `jest.genMockFromModule(moduleName)`
Given the name of a module, use the automatic mocking system to generate a mocked version of the module for you.
@@ -208,9 +154,9 @@ jest.mock(
'../moduleName',
() => {
/*
- * Custom implementation of a module that doesn't exist in JS,
- * like a generated module or a native module in react-native.
- */
+ * Custom implementation of a module that doesn't exist in JS,
+ * like a generated module or a native module in react-native.
+ */
},
{virtual: true},
);
@@ -266,21 +212,25 @@ When using `babel-jest`, calls to `unmock` will automatically be hoisted to the
Returns the `jest` object for chaining.
-### `jest.clearAllMocks()`
+### `jest.setMock(moduleName, moduleExports)`
-Clears the `mock.calls` and `mock.instances` properties of all mocks. Equivalent to calling [`.mockClear()`](MockFunctionAPI.md#mockfnmockclear) on every mocked function.
+Explicitly supplies the mock object that the module system should return for the specified module.
+
+On occasion there are times where the automatically generated mock the module system would normally provide you isn't adequate enough for your testing needs. Normally under those circumstances you should write a [manual mock](ManualMocks.md) that is more adequate for the module in question. However, on extremely rare occasions, even a manual mock isn't suitable for your purposes and you need to build the mock yourself inside your test.
+
+In these rare scenarios you can use this API to manually fill the slot in the module system's mock-module registry.
Returns the `jest` object for chaining.
-### `jest.resetAllMocks()`
+_Note It is recommended to use [`jest.mock()`](#jestmockmodulename-factory-options) instead. The `jest.mock` API's second argument is a module factory instead of the expected exported module object._
-Resets the state of all mocks. Equivalent to calling [`.mockReset()`](MockFunctionAPI.md#mockfnmockreset) on every mocked function.
+### `jest.requireActual(moduleName)`
-Returns the `jest` object for chaining.
+Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not.
-### `jest.restoreAllMocks()`
+### `jest.requireMock(moduleName)`
-Restores all mocks back to their original value. Equivalent to calling [`.mockRestore()`](MockFunctionAPI.md#mockfnmockrestore) on every mocked function. Beware that `jest.restoreAllMocks()` only works when mock was created with `jest.spyOn`; other mocks will require you to manually restore them.
+Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not.
### `jest.resetModules()`
@@ -315,100 +265,25 @@ test('works too', () => {
Returns the `jest` object for chaining.
-### `jest.retryTimes()`
+## Mock functions
-Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus)!
+### `jest.fn(implementation)`
-Example in a test:
+Returns a new, unused [mock function](MockFunctionAPI.md). Optionally takes a mock implementation.
```js
-jest.retryTimes(3);
-test('will fail', () => {
- expect(true).toBe(false);
-});
-```
-
-Returns the `jest` object for chaining.
-
-### `jest.runAllTicks()`
-
-Exhausts the **micro**-task queue (usually interfaced in node via `process.nextTick`).
-
-When this API is called, all pending micro-tasks that have been queued via `process.nextTick` will be executed. Additionally, if those micro-tasks themselves schedule new micro-tasks, those will be continually exhausted until there are no more micro-tasks remaining in the queue.
-
-### `jest.runAllTimers()`
-
-Exhausts the **macro**-task queue (i.e., all tasks queued by `setTimeout()`, `setInterval()`, and `setImmediate()`).
-
-When this API is called, all pending "macro-tasks" that have been queued via `setTimeout()` or `setInterval()` will be executed. Additionally if those macro-tasks themselves schedule new macro-tasks, those will be continually exhausted until there are no more macro-tasks remaining in the queue.
-
-This is often useful for synchronously executing setTimeouts during a test in order to synchronously assert about some behavior that would only happen after the `setTimeout()` or `setInterval()` callbacks executed. See the [Timer mocks](TimerMocks.md) doc for more information.
-
-### `jest.runAllImmediates()`
-
-Exhausts all tasks queued by `setImmediate()`.
-
-### `jest.advanceTimersByTime(msToRun)`
-
-##### renamed in Jest **22.0.0+**
-
-Also under the alias: `.runTimersToTime()`
-
-Executes only the macro task queue (i.e. all tasks queued by `setTimeout()` or `setInterval()` and `setImmediate()`).
-
-When this API is called, all timers are advanced by `msToRun` milliseconds. All pending "macro-tasks" that have been queued via `setTimeout()` or `setInterval()`, and would be executed within this time frame will be executed. Additionally if those macro-tasks schedule new macro-tasks that would be executed within the same time frame, those will be executed until there are no more macro-tasks remaining in the queue, that should be run within `msToRun` milliseconds.
-
-### `jest.runOnlyPendingTimers()`
-
-Executes only the macro-tasks that are currently pending (i.e., only the tasks that have been queued by `setTimeout()` or `setInterval()` up to this point). If any of the currently pending macro-tasks schedule new macro-tasks, those new tasks will not be executed by this call.
-
-This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time.
-
-### `jest.requireActual(moduleName)`
-
-Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not.
-
-### `jest.requireMock(moduleName)`
-
-Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not.
-
-### `jest.setMock(moduleName, moduleExports)`
-
-Explicitly supplies the mock object that the module system should return for the specified module.
-
-On occasion there are times where the automatically generated mock the module system would normally provide you isn't adequate enough for your testing needs. Normally under those circumstances you should write a [manual mock](ManualMocks.md) that is more adequate for the module in question. However, on extremely rare occasions, even a manual mock isn't suitable for your purposes and you need to build the mock yourself inside your test.
-
-In these rare scenarios you can use this API to manually fill the slot in the module system's mock-module registry.
-
-Returns the `jest` object for chaining.
-
-_Note It is recommended to use [`jest.mock()`](#jestmockmodulename-factory-options) instead. The `jest.mock` API's second argument is a module factory instead of the expected exported module object._
-
-### `jest.setTimeout(timeout)`
-
-Set the default timeout interval for tests and before/after hooks in milliseconds.
-
-_Note: The default timeout interval is 5 seconds if this method is not called._
-
-_Note: The method must be called after the test framework is installed in the environment and before the test runs. A good place to do this is in the `setupTestFrameworkScriptFile`._
-
-Example:
+const mockFn = jest.fn();
+mockFn();
+expect(mockFn).toHaveBeenCalled();
-```js
-jest.setTimeout(1000); // 1 second
+// With a mock implementation:
+const returnsTrue = jest.fn(() => true);
+console.log(returnsTrue()); // true;
```
-### `jest.useFakeTimers()`
-
-Instructs Jest to use fake versions of the standard timer functions (`setTimeout`, `setInterval`, `clearTimeout`, `clearInterval`, `nextTick`, `setImmediate` and `clearImmediate`).
-
-Returns the `jest` object for chaining.
-
-### `jest.useRealTimers()`
-
-Instructs Jest to use the real versions of the standard timer functions.
+### `jest.isMockFunction(fn)`
-Returns the `jest` object for chaining.
+Determines if the given function is a mocked function.
### `jest.spyOn(object, methodName)`
@@ -501,3 +376,108 @@ test('plays audio', () => {
spy.mockRestore();
});
```
+
+### `jest.clearAllMocks()`
+
+Clears the `mock.calls` and `mock.instances` properties of all mocks. Equivalent to calling [`.mockClear()`](MockFunctionAPI.md#mockfnmockclear) on every mocked function.
+
+Returns the `jest` object for chaining.
+
+### `jest.resetAllMocks()`
+
+Resets the state of all mocks. Equivalent to calling [`.mockReset()`](MockFunctionAPI.md#mockfnmockreset) on every mocked function.
+
+Returns the `jest` object for chaining.
+
+### `jest.restoreAllMocks()`
+
+Restores all mocks back to their original value. Equivalent to calling [`.mockRestore()`](MockFunctionAPI.md#mockfnmockrestore) on every mocked function. Beware that `jest.restoreAllMocks()` only works when mock was created with `jest.spyOn`; other mocks will require you to manually restore them.
+
+## Mock timers
+
+### `jest.useFakeTimers()`
+
+Instructs Jest to use fake versions of the standard timer functions (`setTimeout`, `setInterval`, `clearTimeout`, `clearInterval`, `nextTick`, `setImmediate` and `clearImmediate`).
+
+Returns the `jest` object for chaining.
+
+### `jest.useRealTimers()`
+
+Instructs Jest to use the real versions of the standard timer functions.
+
+Returns the `jest` object for chaining.
+
+### `jest.runAllTicks()`
+
+Exhausts the **micro**-task queue (usually interfaced in node via `process.nextTick`).
+
+When this API is called, all pending micro-tasks that have been queued via `process.nextTick` will be executed. Additionally, if those micro-tasks themselves schedule new micro-tasks, those will be continually exhausted until there are no more micro-tasks remaining in the queue.
+
+### `jest.runAllTimers()`
+
+Exhausts the **macro**-task queue (i.e., all tasks queued by `setTimeout()`, `setInterval()`, and `setImmediate()`).
+
+When this API is called, all pending "macro-tasks" that have been queued via `setTimeout()` or `setInterval()` will be executed. Additionally if those macro-tasks themselves schedule new macro-tasks, those will be continually exhausted until there are no more macro-tasks remaining in the queue.
+
+This is often useful for synchronously executing setTimeouts during a test in order to synchronously assert about some behavior that would only happen after the `setTimeout()` or `setInterval()` callbacks executed. See the [Timer mocks](TimerMocks.md) doc for more information.
+
+### `jest.runAllImmediates()`
+
+Exhausts all tasks queued by `setImmediate()`.
+
+### `jest.advanceTimersByTime(msToRun)`
+
+##### renamed in Jest **22.0.0+**
+
+Also under the alias: `.runTimersToTime()`
+
+Executes only the macro task queue (i.e. all tasks queued by `setTimeout()` or `setInterval()` and `setImmediate()`).
+
+When this API is called, all timers are advanced by `msToRun` milliseconds. All pending "macro-tasks" that have been queued via `setTimeout()` or `setInterval()`, and would be executed within this time frame will be executed. Additionally if those macro-tasks schedule new macro-tasks that would be executed within the same time frame, those will be executed until there are no more macro-tasks remaining in the queue, that should be run within `msToRun` milliseconds.
+
+### `jest.runOnlyPendingTimers()`
+
+Executes only the macro-tasks that are currently pending (i.e., only the tasks that have been queued by `setTimeout()` or `setInterval()` up to this point). If any of the currently pending macro-tasks schedule new macro-tasks, those new tasks will not be executed by this call.
+
+This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time.
+
+### `jest.clearAllTimers()`
+
+Removes any pending timers from the timer system.
+
+This means, if any timers have been scheduled (but have not yet executed), they will be cleared and will never have the opportunity to execute in the future.
+
+### `jest.getTimerCount()`
+
+Returns the number of fake timers still left to run.
+
+## Misc
+
+### `jest.setTimeout(timeout)`
+
+Set the default timeout interval for tests and before/after hooks in milliseconds.
+
+_Note: The default timeout interval is 5 seconds if this method is not called._
+
+_Note: The method must be called after the test framework is installed in the environment and before the test runs. A good place to do this is in the `setupTestFrameworkScriptFile`._
+
+Example:
+
+```js
+jest.setTimeout(1000); // 1 second
+```
+
+### `jest.retryTimes()`
+
+Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus)!
+
+Example in a test:
+
+```js
+jest.retryTimes(3);
+test('will fail', () => {
+ expect(true).toBe(false);
+});
+```
+
+Returns the `jest` object for chaining.
diff --git a/docs/MockFunctionAPI.md b/docs/MockFunctionAPI.md
index dfdfb7672ac8..199d7a797175 100644
--- a/docs/MockFunctionAPI.md
+++ b/docs/MockFunctionAPI.md
@@ -29,24 +29,30 @@ For example: A mock function `f` that has been called twice, with the arguments
### `mockFn.mock.results`
-An array containing the results of all calls that have been made to this mock function. Each entry in this array is an object containing a boolean `isThrow` property, and a `value` property. `isThrow` is true if the call terminated due to a `throw`, or false if the the call returned normally. The `value` property contains the value that was thrown or returned.
+An array containing the results of all calls that have been made to this mock function. Each entry in this array is an object containing a `type` property, and a `value` property. `type` will be one of the following:
-For example: A mock function `f` that has been called three times, returning `result1`, throwing an error, and then returning `result2`, would have a `mock.results` array that looks like this:
+- `'return'` - Indicates that the call completed by returning normally.
+- `'throw'` - Indicates that the call completed by throwing a value.
+- `'incomplete'` - Indicates that the call has not yet completed. This occurs if you test the result from within the mock function itself, or from within a function that was called by the mock.
+
+The `value` property contains the value that was thrown or returned. `value` is undefined when `type === 'incomplete'`.
+
+For example: A mock function `f` that has been called three times, returning `'result1'`, throwing an error, and then returning `'result2'`, would have a `mock.results` array that looks like this:
```js
[
{
- isThrow: false,
+ type: 'return',
value: 'result1',
},
{
- isThrow: true,
+ type: 'throw',
value: {
/* Error instance */
},
},
{
- isThrow: false,
+ type: 'return',
value: 'result2',
},
];
diff --git a/docs/MockFunctions.md b/docs/MockFunctions.md
index eb96d94ca990..dfc33a7af6f3 100644
--- a/docs/MockFunctions.md
+++ b/docs/MockFunctions.md
@@ -160,9 +160,6 @@ Still, there are cases where it's useful to go beyond the ability to specify ret
```javascript
const myMockFn = jest.fn(cb => cb(null, true));
-myMockFn((err, val) => console.log(val));
-// > true
-
myMockFn((err, val) => console.log(val));
// > true
```
diff --git a/docs/MongoDB.md b/docs/MongoDB.md
index 6d4fcbf88108..2950c2a9c604 100644
--- a/docs/MongoDB.md
+++ b/docs/MongoDB.md
@@ -26,7 +26,7 @@ const {MongoMemoryServer} = require('mongodb-memory-server');
const globalConfigPath = path.join(__dirname, 'globalConfig.json');
-const mongoServer = new MongoMemoryServer({
+const mongod = new MongoMemoryServer({
autoStart: false,
});
@@ -37,14 +37,14 @@ module.exports = async () => {
const mongoConfig = {
mongoDBName: 'jest',
- mongoUri: await mongoServer.getConnectionString(),
+ mongoUri: await mongod.getConnectionString(),
};
// Write global config to disk because all tests run in different contexts.
fs.writeFileSync(globalConfigPath, JSON.stringify(mongoConfig));
// Set reference to mongod in order to close the server during teardown.
- global.__MONGOD__ = mongoServer;
+ global.__MONGOD__ = mongod;
};
```
diff --git a/docs/TutorialAsync.md b/docs/TutorialAsync.md
index c59146e77b9a..2bcd2e69bf34 100644
--- a/docs/TutorialAsync.md
+++ b/docs/TutorialAsync.md
@@ -50,13 +50,12 @@ const users = {
export default function request(url) {
return new Promise((resolve, reject) => {
const userID = parseInt(url.substr('/users/'.length), 10);
- process.nextTick(
- () =>
- users[userID]
- ? resolve(users[userID])
- : reject({
- error: 'User with ' + userID + ' not found.',
- }),
+ process.nextTick(() =>
+ users[userID]
+ ? resolve(users[userID])
+ : reject({
+ error: 'User with ' + userID + ' not found.',
+ }),
);
});
}
diff --git a/docs/TutorialReact.md b/docs/TutorialReact.md
index f8f8938b0986..9fc126fe545a 100644
--- a/docs/TutorialReact.md
+++ b/docs/TutorialReact.md
@@ -208,9 +208,11 @@ React 16 triggers these warnings due to how it checks element types, and the moc
### DOM Testing
-If you'd like to assert, and manipulate your rendered components you can use [Enzyme](http://airbnb.io/enzyme/) or React's [TestUtils](http://facebook.github.io/react/docs/test-utils.html). We use Enzyme for this example.
+If you'd like to assert, and manipulate your rendered components you can use [react-testing-library](https://github.com/kentcdodds/react-testing-library), [Enzyme](http://airbnb.io/enzyme/), or React's [TestUtils](http://facebook.github.io/react/docs/test-utils.html). The following two examples use react-testing-library and Enzyme.
-You have to run `yarn add --dev enzyme` to use Enzyme. If you are using a React version below 15.5.0, you will also need to install `react-addons-test-utils`.
+#### react-testing-library
+
+You have to run `yarn add --dev react-testing-library` to use react-testing-library.
Let's implement a simple checkbox which swaps between two labels:
@@ -248,7 +250,35 @@ export default class CheckboxWithLabel extends React.Component {
}
```
-We use Enzyme's [shallow renderer](http://airbnb.io/enzyme/docs/api/shallow.html) in this example.
+```javascript
+// __tests__/CheckboxWithLabel-test.js
+import React from 'react';
+import {render, fireEvent, cleanup} from 'react-testing-library';
+import CheckboxWithLabel from '../CheckboxWithLabel';
+
+// automatically unmount and cleanup DOM after the test is finished.
+afterEach(cleanup);
+
+it('CheckboxWithLabel changes the text after click', () => {
+ const {queryByLabelText, getByLabelText} = render(
+ ,
+ );
+
+ expect(queryByLabelText(/off/i)).toBeTruthy();
+
+ fireEvent.click(getByLabelText(/off/i));
+
+ expect(queryByLabelText(/on/i)).toBeTruthy();
+});
+```
+
+The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/master/examples/react-testing-library).
+
+#### Enzyme
+
+You have to run `yarn add --dev enzyme` to use Enzyme. If you are using a React version below 15.5.0, you will also need to install `react-addons-test-utils`.
+
+Let's rewrite the test from above using Enzyme instead of react-testing-library. We use Enzyme's [shallow renderer](http://airbnb.io/enzyme/docs/api/shallow.html) in this example.
```javascript
// __tests__/CheckboxWithLabel-test.js
diff --git a/e2e/__tests__/__snapshots__/coverage_remapping.test.js.snap b/e2e/__tests__/__snapshots__/coverage_remapping.test.js.snap
index 00cebd87ecb8..7285790c0bbf 100644
--- a/e2e/__tests__/__snapshots__/coverage_remapping.test.js.snap
+++ b/e2e/__tests__/__snapshots__/coverage_remapping.test.js.snap
@@ -26,33 +26,33 @@ Object {
"0": Object {
"loc": Object {
"end": Object {
- "column": 9,
- "line": 5,
+ "column": 35,
+ "line": 4,
},
"start": Object {
- "column": 8,
- "line": 5,
+ "column": 34,
+ "line": 4,
},
},
"locations": Array [
Object {
"end": Object {
- "column": 9,
- "line": 5,
+ "column": 35,
+ "line": 4,
},
"start": Object {
- "column": 8,
- "line": 5,
+ "column": 34,
+ "line": 4,
},
},
Object {
"end": Object {
- "column": 9,
- "line": 6,
+ "column": 39,
+ "line": 4,
},
"start": Object {
- "column": 8,
- "line": 6,
+ "column": 38,
+ "line": 4,
},
},
],
@@ -61,33 +61,33 @@ Object {
"1": Object {
"loc": Object {
"end": Object {
- "column": 37,
- "line": 7,
+ "column": 35,
+ "line": 5,
},
"start": Object {
- "column": 36,
- "line": 7,
+ "column": 34,
+ "line": 5,
},
},
"locations": Array [
Object {
"end": Object {
- "column": 37,
- "line": 7,
+ "column": 35,
+ "line": 5,
},
"start": Object {
- "column": 36,
- "line": 7,
+ "column": 34,
+ "line": 5,
},
},
Object {
"end": Object {
- "column": 41,
- "line": 7,
+ "column": 39,
+ "line": 5,
},
"start": Object {
- "column": 40,
- "line": 7,
+ "column": 38,
+ "line": 5,
},
},
],
@@ -96,43 +96,43 @@ Object {
"2": Object {
"loc": Object {
"end": Object {
- "column": 33,
- "line": 8,
+ "column": 31,
+ "line": 6,
},
"start": Object {
- "column": 29,
- "line": 8,
+ "column": 27,
+ "line": 6,
},
},
"locations": Array [
Object {
"end": Object {
- "column": 33,
- "line": 8,
+ "column": 31,
+ "line": 6,
},
"start": Object {
- "column": 29,
- "line": 8,
+ "column": 27,
+ "line": 6,
},
},
Object {
"end": Object {
- "column": 41,
- "line": 8,
+ "column": 39,
+ "line": 6,
},
"start": Object {
- "column": 37,
- "line": 8,
+ "column": 35,
+ "line": 6,
},
},
Object {
"end": Object {
- "column": 50,
- "line": 8,
+ "column": 48,
+ "line": 6,
},
"start": Object {
- "column": 45,
- "line": 8,
+ "column": 43,
+ "line": 6,
},
},
],
@@ -141,33 +141,33 @@ Object {
"3": Object {
"loc": Object {
"end": Object {
- "column": 42,
- "line": 9,
+ "column": 40,
+ "line": 7,
},
"start": Object {
- "column": 32,
- "line": 9,
+ "column": 30,
+ "line": 7,
},
},
"locations": Array [
Object {
"end": Object {
- "column": 42,
- "line": 9,
+ "column": 40,
+ "line": 7,
},
"start": Object {
- "column": 32,
- "line": 9,
+ "column": 30,
+ "line": 7,
},
},
Object {
"end": Object {
- "column": 55,
- "line": 9,
+ "column": 53,
+ "line": 7,
},
"start": Object {
- "column": 45,
- "line": 9,
+ "column": 43,
+ "line": 7,
},
},
],
@@ -194,7 +194,7 @@ Object {
"loc": Object {
"end": Object {
"column": 1,
- "line": 12,
+ "line": 10,
},
"start": Object {
"column": 49,
@@ -206,22 +206,22 @@ Object {
"1": Object {
"decl": Object {
"end": Object {
- "column": 37,
- "line": 9,
+ "column": 35,
+ "line": 7,
},
"start": Object {
- "column": 32,
- "line": 9,
+ "column": 30,
+ "line": 7,
},
},
"loc": Object {
"end": Object {
- "column": 42,
- "line": 9,
+ "column": 40,
+ "line": 7,
},
"start": Object {
- "column": 32,
- "line": 9,
+ "column": 30,
+ "line": 7,
},
},
"name": "(anonymous_1)",
@@ -229,22 +229,22 @@ Object {
"2": Object {
"decl": Object {
"end": Object {
- "column": 50,
- "line": 9,
+ "column": 48,
+ "line": 7,
},
"start": Object {
- "column": 45,
- "line": 9,
+ "column": 43,
+ "line": 7,
},
},
"loc": Object {
"end": Object {
- "column": 55,
- "line": 9,
+ "column": 53,
+ "line": 7,
},
"start": Object {
- "column": 45,
- "line": 9,
+ "column": 43,
+ "line": 7,
},
},
"name": "(anonymous_2)",
@@ -264,8 +264,8 @@ Object {
"statementMap": Object {
"0": Object {
"end": Object {
- "column": 1,
- "line": 12,
+ "column": 2,
+ "line": 10,
},
"start": Object {
"column": 0,
@@ -274,72 +274,72 @@ Object {
},
"1": Object {
"end": Object {
- "column": 9,
- "line": 6,
+ "column": 39,
+ "line": 4,
},
"start": Object {
- "column": 29,
+ "column": 27,
"line": 4,
},
},
"2": Object {
"end": Object {
- "column": 41,
- "line": 7,
+ "column": 39,
+ "line": 5,
},
"start": Object {
- "column": 29,
- "line": 7,
+ "column": 27,
+ "line": 5,
},
},
"3": Object {
"end": Object {
- "column": 50,
- "line": 8,
+ "column": 48,
+ "line": 6,
},
"start": Object {
- "column": 29,
- "line": 8,
+ "column": 27,
+ "line": 6,
},
},
"4": Object {
"end": Object {
- "column": 55,
- "line": 9,
+ "column": 53,
+ "line": 7,
},
"start": Object {
- "column": 25,
- "line": 9,
+ "column": 23,
+ "line": 7,
},
},
"5": Object {
"end": Object {
- "column": 42,
- "line": 9,
+ "column": 40,
+ "line": 7,
},
"start": Object {
- "column": 38,
- "line": 9,
+ "column": 36,
+ "line": 7,
},
},
"6": Object {
"end": Object {
- "column": 55,
- "line": 9,
+ "column": 53,
+ "line": 7,
},
"start": Object {
- "column": 51,
- "line": 9,
+ "column": 49,
+ "line": 7,
},
},
"7": Object {
"end": Object {
- "column": 17,
- "line": 11,
+ "column": 15,
+ "line": 9,
},
"start": Object {
- "column": 4,
- "line": 11,
+ "column": 2,
+ "line": 9,
},
},
},
diff --git a/e2e/__tests__/__snapshots__/expect-async-matcher.test.js.snap b/e2e/__tests__/__snapshots__/expect-async-matcher.test.js.snap
index 500651f28854..21773aab847b 100644
--- a/e2e/__tests__/__snapshots__/expect-async-matcher.test.js.snap
+++ b/e2e/__tests__/__snapshots__/expect-async-matcher.test.js.snap
@@ -9,9 +9,8 @@ exports[`shows the correct errors in stderr when failing tests 1`] = `
● fail with expected non promise values
- Error
+ Expected value to have length:
- Error: Expected value to have length:
2
Received:
1
@@ -20,9 +19,8 @@ exports[`shows the correct errors in stderr when failing tests 1`] = `
● fail with expected non promise values and not
- Error
+ Expected value to not have length:
- Error: Expected value to not have length:
2
Received:
1,2
diff --git a/e2e/__tests__/__snapshots__/failures.test.js.snap b/e2e/__tests__/__snapshots__/failures.test.js.snap
index f98d981662eb..8388356e0763 100644
--- a/e2e/__tests__/__snapshots__/failures.test.js.snap
+++ b/e2e/__tests__/__snapshots__/failures.test.js.snap
@@ -13,9 +13,7 @@ exports[`not throwing Error objects 2`] = `
"FAIL __tests__/throw_string.test.js
● Test suite failed to run
- Error
-
- banana
+ banana
"
`;
@@ -387,8 +385,8 @@ exports[`works with async failures 1`] = `
> 21 | expect(Promise.reject({foo: 'bar'})).resolves.toEqual({foo: 'bar'}));
| ^
22 |
- 23 | test(
- 24 | 'timeout',
+ 23 | test('timeout', done => {
+ 24 | setTimeout(done, 50);
at __tests__/async_failures.test.js:21:3
@@ -398,11 +396,11 @@ exports[`works with async failures 1`] = `
21 | expect(Promise.reject({foo: 'bar'})).resolves.toEqual({foo: 'bar'}));
22 |
- > 23 | test(
+ > 23 | test('timeout', done => {
| ^
- 24 | 'timeout',
- 25 | done => {
- 26 | setTimeout(done, 50);
+ 24 | setTimeout(done, 50);
+ 25 | }, 5);
+ 26 |
at __tests__/async_failures.test.js:23:1
diff --git a/e2e/__tests__/__snapshots__/show_config.test.js.snap b/e2e/__tests__/__snapshots__/show_config.test.js.snap
index f3982dde87f3..24f419707d6d 100644
--- a/e2e/__tests__/__snapshots__/show_config.test.js.snap
+++ b/e2e/__tests__/__snapshots__/show_config.test.js.snap
@@ -13,6 +13,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
\\"/node_modules/\\"
],
\\"cwd\\": \\"<>\\",
+ \\"dependencyExtractor\\": null,
\\"detectLeaks\\": false,
\\"detectOpenHandles\\": false,
\\"errorOnDeprecated\\": false,
@@ -20,6 +21,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
\\"forceCoverageMatch\\": [],
\\"globals\\": {},
\\"haste\\": {
+ \\"computeSha1\\": false,
\\"providesModuleNodeModules\\": []
},
\\"moduleDirectories\\": [
diff --git a/e2e/__tests__/find_related_files.test.js b/e2e/__tests__/find_related_files.test.js
index 2024e1dd97e5..a9ddf9f2c3c7 100644
--- a/e2e/__tests__/find_related_files.test.js
+++ b/e2e/__tests__/find_related_files.test.js
@@ -41,6 +41,48 @@ describe('--findRelatedTests flag', () => {
expect(stderr).toMatch(summaryMsg);
});
+ test('runs tests related to filename with a custom dependency extractor', () => {
+ writeFiles(DIR, {
+ '.watchmanconfig': '',
+ '__tests__/test.test.js': `
+ const dynamicImport = path => Promise.resolve(require(path));
+ test('a', () => dynamicImport('../a').then(a => {
+ expect(a.foo).toBe(5);
+ }));
+ `,
+ 'a.js': 'module.exports = {foo: 5};',
+ 'dependencyExtractor.js': `
+ const DYNAMIC_IMPORT_RE = /(?:^|[^.]\\s*)(\\bdynamicImport\\s*?\\(\\s*?)([\`'"])([^\`'"]+)(\\2\\s*?\\))/g;
+ module.exports = {
+ extract(code) {
+ const dependencies = new Set();
+ const addDependency = (match, pre, quot, dep, post) => {
+ dependencies.add(dep);
+ return match;
+ };
+ code.replace(DYNAMIC_IMPORT_RE, addDependency);
+ return dependencies;
+ },
+ };
+ `,
+ 'package.json': JSON.stringify({
+ jest: {
+ dependencyExtractor: '/dependencyExtractor.js',
+ testEnvironment: 'node',
+ },
+ }),
+ });
+
+ const {stdout} = runJest(DIR, ['a.js']);
+ expect(stdout).toMatch('');
+
+ const {stderr} = runJest(DIR, ['--findRelatedTests', 'a.js']);
+ expect(stderr).toMatch('PASS __tests__/test.test.js');
+
+ const summaryMsg = 'Ran all test suites related to files matching /a.js/i.';
+ expect(stderr).toMatch(summaryMsg);
+ });
+
test('generates coverage report for filename', () => {
writeFiles(DIR, {
'.watchmanconfig': '',
diff --git a/e2e/__tests__/override-globals.test.js b/e2e/__tests__/override-globals.test.js
index a8ad8ac7c252..489f43e76987 100644
--- a/e2e/__tests__/override-globals.test.js
+++ b/e2e/__tests__/override-globals.test.js
@@ -15,3 +15,14 @@ test('overriding native promise does not freeze Jest', () => {
const run = runJest('override-globals');
expect(run.stderr).toMatch(/PASS __tests__(\/|\\)index.js/);
});
+
+test('has a duration even if time is faked', () => {
+ const regex = /works well \((\d+)ms\)/;
+ const {stderr} = runJest('override-globals', ['--verbose']);
+
+ expect(stderr).toMatch(regex);
+
+ const [, duration] = stderr.match(regex);
+
+ expect(Number(duration)).toBeGreaterThan(0);
+});
diff --git a/e2e/coverage-remapping/covered.ts b/e2e/coverage-remapping/covered.ts
index df5496159f87..28b8d10b0668 100644
--- a/e2e/coverage-remapping/covered.ts
+++ b/e2e/coverage-remapping/covered.ts
@@ -1,12 +1,10 @@
// Copyright 2004-present Facebook. All Rights Reserved.
export = function difference(a: number, b: number): number {
- const branch1: boolean = true
- ? 1
- : 0;
- const branch2: boolean = true ? 1 : 0;
- const branch3: boolean = true || true || false;
- const fn: Function = true ? () => null : () => null;
+ const branch1: boolean = true ? 1 : 0;
+ const branch2: boolean = true ? 1 : 0;
+ const branch3: boolean = true || true || false;
+ const fn: Function = true ? () => null : () => null;
- return a - b;
-}
+ return a - b;
+};
diff --git a/e2e/custom-reporters/package.json b/e2e/custom-reporters/package.json
index 590f11ffe692..c08385980ac4 100644
--- a/e2e/custom-reporters/package.json
+++ b/e2e/custom-reporters/package.json
@@ -1,11 +1,14 @@
{
"jest": {
"reporters": [
- ["/reporters/TestReporter.js", {
- "hello": "world",
- "dmitrii": "abramov",
- "christoph": "pojer"
- }]
+ [
+ "/reporters/TestReporter.js",
+ {
+ "hello": "world",
+ "dmitrii": "abramov",
+ "christoph": "pojer"
+ }
+ ]
]
}
}
diff --git a/e2e/custom-resolver/resolver.js b/e2e/custom-resolver/resolver.js
index 7385bfdd28c4..e9a718b139b5 100644
--- a/e2e/custom-resolver/resolver.js
+++ b/e2e/custom-resolver/resolver.js
@@ -2,7 +2,7 @@
const {
default: defaultResolver,
-} = require('jest-resolve/build/default_resolver');
+} = require('jest-resolve/build/defaultResolver');
const exportedModules = new Map([
['foo', 'foo'],
diff --git a/e2e/failures/__tests__/async_failures.test.js b/e2e/failures/__tests__/async_failures.test.js
index 9eaafa3a8878..b78eecd6f4bd 100644
--- a/e2e/failures/__tests__/async_failures.test.js
+++ b/e2e/failures/__tests__/async_failures.test.js
@@ -20,10 +20,6 @@ test('expect reject', () =>
test('expect resolve', () =>
expect(Promise.reject({foo: 'bar'})).resolves.toEqual({foo: 'bar'}));
-test(
- 'timeout',
- done => {
- setTimeout(done, 50);
- },
- 5
-);
+test('timeout', done => {
+ setTimeout(done, 50);
+}, 5);
diff --git a/e2e/jasmine-async/__tests__/promise_before_all.test.js b/e2e/jasmine-async/__tests__/promise_before_all.test.js
index 1907239d42f5..b4f1df734707 100644
--- a/e2e/jasmine-async/__tests__/promise_before_all.test.js
+++ b/e2e/jasmine-async/__tests__/promise_before_all.test.js
@@ -15,7 +15,8 @@ describe('promise beforeAll', () => {
process.nextTick(resolve);
}).then(() => {
flag = 1;
- }));
+ })
+ );
beforeAll(() => new Promise(resolve => setTimeout(resolve, 10)), 500);
diff --git a/e2e/jasmine-async/__tests__/promise_before_each.test.js b/e2e/jasmine-async/__tests__/promise_before_each.test.js
index 53570b9126f0..dbb7fdbc206a 100644
--- a/e2e/jasmine-async/__tests__/promise_before_each.test.js
+++ b/e2e/jasmine-async/__tests__/promise_before_each.test.js
@@ -13,7 +13,8 @@ describe('promise beforeEach', () => {
process.nextTick(resolve);
}).then(() => {
this.flag = 1;
- }));
+ })
+ );
// passing tests
it('runs tests after beforeEach asynchronously completes', () => {
diff --git a/e2e/json-reporter/package.json b/e2e/json-reporter/package.json
index d59562604cad..781ddcb77c5a 100644
--- a/e2e/json-reporter/package.json
+++ b/e2e/json-reporter/package.json
@@ -1,6 +1,8 @@
{
"jest": {
"testEnvironment": "node",
- "coverageReporters": ["json"]
+ "coverageReporters": [
+ "json"
+ ]
}
}
diff --git a/e2e/multi-project-config-root/package.json b/e2e/multi-project-config-root/package.json
index 58e129a79e90..897e521d1dc8 100644
--- a/e2e/multi-project-config-root/package.json
+++ b/e2e/multi-project-config-root/package.json
@@ -1,18 +1,18 @@
{
"jest": {
"projects": [
- {
- "rootDir": "/foo",
- "testPathIgnorePatterns": [
- "/__tests__/boggus-foo.test.js"
- ]
- },
- {
- "rootDir": "/bar",
- "testPathIgnorePatterns": [
- "/__tests__/boggus-bar.test.js"
- ]
- }
+ {
+ "rootDir": "/foo",
+ "testPathIgnorePatterns": [
+ "/__tests__/boggus-foo.test.js"
+ ]
+ },
+ {
+ "rootDir": "/bar",
+ "testPathIgnorePatterns": [
+ "/__tests__/boggus-bar.test.js"
+ ]
+ }
]
}
}
diff --git a/e2e/override-globals/package.json b/e2e/override-globals/package.json
index 148788b25446..b4a435775e2b 100644
--- a/e2e/override-globals/package.json
+++ b/e2e/override-globals/package.json
@@ -1,5 +1,8 @@
{
"jest": {
- "testEnvironment": "node"
+ "testEnvironment": "node",
+ "setupFiles": [
+ "/setup.js"
+ ]
}
}
diff --git a/e2e/override-globals/setup.js b/e2e/override-globals/setup.js
new file mode 100644
index 000000000000..ade70a19010f
--- /dev/null
+++ b/e2e/override-globals/setup.js
@@ -0,0 +1,9 @@
+/**
+ * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+Date.now = () => 0;
+process.hrtime = () => [0, 5000];
diff --git a/e2e/resolve-node-module/package.json b/e2e/resolve-node-module/package.json
index 0a586922137e..7c329bea6ee6 100644
--- a/e2e/resolve-node-module/package.json
+++ b/e2e/resolve-node-module/package.json
@@ -1,6 +1,10 @@
{
"jest": {
- "moduleFileExtensions": ["js", "json", "jsx"],
+ "moduleFileExtensions": [
+ "js",
+ "json",
+ "jsx"
+ ],
"testEnvironment": "node"
}
}
diff --git a/e2e/resolve/__tests__/resolve.test.js b/e2e/resolve/__tests__/resolve.test.js
index 41a840c2d56d..e8a5571f59ef 100644
--- a/e2e/resolve/__tests__/resolve.test.js
+++ b/e2e/resolve/__tests__/resolve.test.js
@@ -47,6 +47,11 @@ test('should resolve filename.native.js', () => {
expect(platform.extension).toBe('native.js');
});
+test('should resolve filename.native.js with moduleNameMapper', () => {
+ expect(testRequire('test2mapper')).not.toThrow();
+ expect(platform.extension).toBe('native.js');
+});
+
test('should resolve filename.js', () => {
expect(testRequire('../test3')).not.toThrow();
expect(platform.extension).toBe('js');
diff --git a/e2e/resolve/package.json b/e2e/resolve/package.json
index 743e0a83f202..f3feb16b420f 100644
--- a/e2e/resolve/package.json
+++ b/e2e/resolve/package.json
@@ -2,9 +2,14 @@
"name": "custom-resolve",
"jest": {
"haste": {
- "platforms": ["native"],
+ "platforms": [
+ "native"
+ ],
"defaultPlatform": "android"
},
- "testEnvironment": "node"
+ "testEnvironment": "node",
+ "moduleNameMapper": {
+ "test2mapper": "/test2mapper"
+ }
}
}
diff --git a/e2e/resolve/test1.json b/e2e/resolve/test1.json
index 13827d9bbdc0..001968d98e1b 100644
--- a/e2e/resolve/test1.json
+++ b/e2e/resolve/test1.json
@@ -1,3 +1,3 @@
{
- "extension": "json"
+ "extension": "json"
}
diff --git a/e2e/resolve/test2.json b/e2e/resolve/test2.json
index 13827d9bbdc0..001968d98e1b 100644
--- a/e2e/resolve/test2.json
+++ b/e2e/resolve/test2.json
@@ -1,3 +1,3 @@
{
- "extension": "json"
+ "extension": "json"
}
diff --git a/e2e/resolve/test2mapper.js b/e2e/resolve/test2mapper.js
new file mode 100644
index 000000000000..a265d4b021c8
--- /dev/null
+++ b/e2e/resolve/test2mapper.js
@@ -0,0 +1,8 @@
+/**
+ * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+module.exports = {extension: '.js'};
diff --git a/e2e/resolve/test2mapper.native.js b/e2e/resolve/test2mapper.native.js
new file mode 100644
index 000000000000..68a290a4b715
--- /dev/null
+++ b/e2e/resolve/test2mapper.native.js
@@ -0,0 +1,8 @@
+/**
+ * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+module.exports = {extension: 'native.js'};
diff --git a/e2e/resolve/test3.json b/e2e/resolve/test3.json
index 13827d9bbdc0..001968d98e1b 100644
--- a/e2e/resolve/test3.json
+++ b/e2e/resolve/test3.json
@@ -1,3 +1,3 @@
{
- "extension": "json"
+ "extension": "json"
}
diff --git a/e2e/resolve/test4.json b/e2e/resolve/test4.json
index 13827d9bbdc0..001968d98e1b 100644
--- a/e2e/resolve/test4.json
+++ b/e2e/resolve/test4.json
@@ -1,3 +1,3 @@
{
- "extension": "json"
+ "extension": "json"
}
diff --git a/e2e/stack-trace-source-maps/package.json b/e2e/stack-trace-source-maps/package.json
index cb29f0b9a69a..8941387eb502 100644
--- a/e2e/stack-trace-source-maps/package.json
+++ b/e2e/stack-trace-source-maps/package.json
@@ -5,7 +5,10 @@
"^.+\\.(ts)$": "/Preprocessor.js"
},
"testEnvironment": "node",
- "moduleFileExtensions": ["ts", "js"],
+ "moduleFileExtensions": [
+ "ts",
+ "js"
+ ],
"testRegex": "fails"
},
"dependencies": {
diff --git a/e2e/transform/ecmascript-modules-support/package.json b/e2e/transform/ecmascript-modules-support/package.json
index b3145fb854df..d37c7ca66af6 100644
--- a/e2e/transform/ecmascript-modules-support/package.json
+++ b/e2e/transform/ecmascript-modules-support/package.json
@@ -1,8 +1,16 @@
{
"jest": {
"testEnvironment": "node",
- "moduleFileExtensions": ["js", "json", "jsx", "node", "mjs"],
- "testMatch": [ "**/__tests__/**/*.mjs"],
+ "moduleFileExtensions": [
+ "js",
+ "json",
+ "jsx",
+ "node",
+ "mjs"
+ ],
+ "testMatch": [
+ "**/__tests__/**/*.mjs"
+ ],
"transform": {
"^.+\\.mjs?$": "../../../packages/babel-jest"
}
diff --git a/e2e/transform/no-babel-jest/package.json b/e2e/transform/no-babel-jest/package.json
index 86982fa93b05..9fb09b127a3b 100644
--- a/e2e/transform/no-babel-jest/package.json
+++ b/e2e/transform/no-babel-jest/package.json
@@ -4,7 +4,9 @@
"/this-directory-is-covered/Covered.js": true,
"/this-directory-is-covered/ExcludedFromCoverage.js": true
},
- "coveragePathIgnorePatterns": ["ExcludedFromCoverage"],
+ "coveragePathIgnorePatterns": [
+ "ExcludedFromCoverage"
+ ],
"testEnvironment": "node"
}
}
diff --git a/e2e/typescript-coverage/package.json b/e2e/typescript-coverage/package.json
index 4c274920cbe4..9b6cf144b886 100644
--- a/e2e/typescript-coverage/package.json
+++ b/e2e/typescript-coverage/package.json
@@ -4,7 +4,9 @@
"transform": {
"^.+\\.(ts|js)$": "/TypescriptPreprocessor.js"
},
- "testMatch": ["**/__tests__/*.+(ts|tsx|js)"],
+ "testMatch": [
+ "**/__tests__/*.+(ts|tsx|js)"
+ ],
"testEnvironment": "node",
"moduleFileExtensions": [
"ts",
diff --git a/examples/async/__mocks__/request.js b/examples/async/__mocks__/request.js
index 3dc3d9451003..51784974d8fa 100644
--- a/examples/async/__mocks__/request.js
+++ b/examples/async/__mocks__/request.js
@@ -10,13 +10,12 @@ const users = {
export default function request(url) {
return new Promise((resolve, reject) => {
const userID = parseInt(url.substr('/users/'.length), 10);
- process.nextTick(
- () =>
- users[userID]
- ? resolve(users[userID])
- : reject({
- error: 'User with ' + userID + ' not found.',
- })
+ process.nextTick(() =>
+ users[userID]
+ ? resolve(users[userID])
+ : reject({
+ error: 'User with ' + userID + ' not found.',
+ })
);
});
}
diff --git a/examples/enzyme/__tests__/checkbox_with_label.test.js b/examples/enzyme/__tests__/CheckboxWithLabel-test.js
similarity index 100%
rename from examples/enzyme/__tests__/checkbox_with_label.test.js
rename to examples/enzyme/__tests__/CheckboxWithLabel-test.js
diff --git a/examples/react-native/ios/jestrn/Images.xcassets/AppIcon.appiconset/Contents.json b/examples/react-native/ios/jestrn/Images.xcassets/AppIcon.appiconset/Contents.json
index d3942e941ae8..48e64ae8a3ef 100644
--- a/examples/react-native/ios/jestrn/Images.xcassets/AppIcon.appiconset/Contents.json
+++ b/examples/react-native/ios/jestrn/Images.xcassets/AppIcon.appiconset/Contents.json
@@ -1,38 +1,38 @@
{
- "images" : [
+ "images": [
{
- "idiom" : "iphone",
- "size" : "29x29",
- "scale" : "2x"
+ "idiom": "iphone",
+ "size": "29x29",
+ "scale": "2x"
},
{
- "idiom" : "iphone",
- "size" : "29x29",
- "scale" : "3x"
+ "idiom": "iphone",
+ "size": "29x29",
+ "scale": "3x"
},
{
- "idiom" : "iphone",
- "size" : "40x40",
- "scale" : "2x"
+ "idiom": "iphone",
+ "size": "40x40",
+ "scale": "2x"
},
{
- "idiom" : "iphone",
- "size" : "40x40",
- "scale" : "3x"
+ "idiom": "iphone",
+ "size": "40x40",
+ "scale": "3x"
},
{
- "idiom" : "iphone",
- "size" : "60x60",
- "scale" : "2x"
+ "idiom": "iphone",
+ "size": "60x60",
+ "scale": "2x"
},
{
- "idiom" : "iphone",
- "size" : "60x60",
- "scale" : "3x"
+ "idiom": "iphone",
+ "size": "60x60",
+ "scale": "3x"
}
],
- "info" : {
- "version" : 1,
- "author" : "xcode"
+ "info": {
+ "version": 1,
+ "author": "xcode"
}
}
diff --git a/examples/react-testing-library/CheckboxWithLabel.js b/examples/react-testing-library/CheckboxWithLabel.js
new file mode 100644
index 000000000000..ccad8995d978
--- /dev/null
+++ b/examples/react-testing-library/CheckboxWithLabel.js
@@ -0,0 +1,31 @@
+// Copyright 2004-present Facebook. All Rights Reserved.
+
+import React from 'react';
+
+export default class CheckboxWithLabel extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {isChecked: false};
+
+ // bind manually because React class components don't auto-bind
+ // http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding
+ this.onChange = this.onChange.bind(this);
+ }
+
+ onChange() {
+ this.setState({isChecked: !this.state.isChecked});
+ }
+
+ render() {
+ return (
+
+ );
+ }
+}
diff --git a/examples/react-testing-library/__tests__/CheckboxWithLabel-test.js b/examples/react-testing-library/__tests__/CheckboxWithLabel-test.js
new file mode 100644
index 000000000000..cd3cf4832b94
--- /dev/null
+++ b/examples/react-testing-library/__tests__/CheckboxWithLabel-test.js
@@ -0,0 +1,20 @@
+// Copyright 2004-present Facebook. All Rights Reserved.
+
+import React from 'react';
+import {render, fireEvent, cleanup} from 'react-testing-library';
+import CheckboxWithLabel from '../CheckboxWithLabel';
+
+// automatically unmount and cleanup DOM after the test is finished.
+afterEach(cleanup);
+
+it('CheckboxWithLabel changes the text after click', () => {
+ const {queryByLabelText, getByLabelText} = render(
+
+ );
+
+ expect(queryByLabelText(/off/i)).toBeTruthy();
+
+ fireEvent.click(getByLabelText(/off/i));
+
+ expect(queryByLabelText(/on/i)).toBeTruthy();
+});
diff --git a/examples/react-testing-library/babel.config.js b/examples/react-testing-library/babel.config.js
new file mode 100644
index 000000000000..f671719a831e
--- /dev/null
+++ b/examples/react-testing-library/babel.config.js
@@ -0,0 +1,3 @@
+module.exports = {
+ presets: ['@babel/preset-env', '@babel/preset-react'],
+};
diff --git a/examples/react-testing-library/package.json b/examples/react-testing-library/package.json
new file mode 100644
index 000000000000..094c9863557b
--- /dev/null
+++ b/examples/react-testing-library/package.json
@@ -0,0 +1,19 @@
+{
+ "private": true,
+ "version": "0.0.0",
+ "name": "example-react-testing-library",
+ "dependencies": {
+ "react": "^16.4.0",
+ "react-dom": "^16.4.0"
+ },
+ "devDependencies": {
+ "@babel/preset-env": "*",
+ "@babel/preset-react": "*",
+ "babel-jest": "*",
+ "react-testing-library": "*",
+ "jest": "*"
+ },
+ "scripts": {
+ "test": "jest"
+ }
+}
diff --git a/examples/react/__tests__/checkbox_with_label.test.js b/examples/react/__tests__/CheckboxWithLabel-test.js
similarity index 100%
rename from examples/react/__tests__/checkbox_with_label.test.js
rename to examples/react/__tests__/CheckboxWithLabel-test.js
diff --git a/examples/typescript/__tests__/checkbox_with_label.test.tsx b/examples/typescript/__tests__/CheckboxWithLabel-test.tsx
similarity index 100%
rename from examples/typescript/__tests__/checkbox_with_label.test.tsx
rename to examples/typescript/__tests__/CheckboxWithLabel-test.tsx
diff --git a/jest.config.js b/jest.config.js
index 06cb6ca2e84c..9a7e9b0808ce 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -25,7 +25,7 @@ module.exports = {
projects: ['', '/examples/*/'],
setupFilesAfterEnv: ['/testSetupFile.js'],
snapshotSerializers: [
- '/packages/pretty-format/build/plugins/convert_ansi.js',
+ '/packages/pretty-format/build/plugins/ConvertAnsi.js',
],
testEnvironment: './packages/jest-environment-node',
testPathIgnorePatterns: [
@@ -35,11 +35,12 @@ module.exports = {
'\\.snap$',
'/packages/.*/build',
'/packages/.*/build-es5',
- '/packages/.*/src/__tests__/expect_util.js',
+ '/packages/.*/src/__tests__/getPrettyPrint.js',
'/packages/jest-cli/src/__tests__/test_root',
'/packages/jest-cli/src/__tests__/__fixtures__/',
'/packages/jest-cli/src/lib/__tests__/fixtures/',
'/packages/jest-haste-map/src/__tests__/haste_impl.js',
+ '/packages/jest-haste-map/src/__tests__/dependencyExtractor.js',
'/packages/jest-resolve-dependencies/src/__tests__/__fixtures__/',
'/packages/jest-runtime/src/__tests__/defaultResolver.js',
'/packages/jest-runtime/src/__tests__/module_dir/',
diff --git a/package.json b/package.json
index 3f1798564d10..bdae6d287631 100644
--- a/package.json
+++ b/package.json
@@ -16,20 +16,21 @@
"codecov": "^3.0.0",
"debug": "^4.0.1",
"eslint": "^5.6.0",
- "eslint-config-prettier": "^3.0.1",
+ "eslint-config-prettier": "^3.1.0",
"eslint-plugin-babel": "^5.1.0",
"eslint-plugin-flowtype": "^2.35.0",
"eslint-plugin-import": "^2.6.0",
- "eslint-plugin-jest": "^21.0.0",
+ "eslint-plugin-jest": "^22.0.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-markdown": "^1.0.0-beta.6",
- "eslint-plugin-prettier": "^2.3.1",
+ "eslint-plugin-prettier": "^2.7.0",
"eslint-plugin-react": "^7.1.0",
"eslint-plugin-relay": "~0.0.19",
"execa": "^1.0.0",
- "flow-bin": "^0.80.0",
+ "flow-bin": "^0.85.0",
"glob": "^7.1.1",
"graceful-fs": "^4.1.11",
+ "isbinaryfile": "^3.0.3",
"istanbul-api": "^2.0.6",
"istanbul-lib-coverage": "^2.0.1",
"jasmine-reporters": "^2.2.0",
@@ -46,7 +47,7 @@
"mkdirp": "^0.5.1",
"mocha": "^5.0.1",
"mock-fs": "^4.4.1",
- "prettier": "^1.13.3",
+ "prettier": "^1.15.2",
"prettylint": "^1.0.0",
"progress": "^2.0.0",
"promise": "^8.0.2",
@@ -71,6 +72,7 @@
"scripts": {
"build-clean": "rm -rf ./packages/*/build ./packages/*/build-es5",
"build": "node ./scripts/build.js",
+ "check-copyright-headers": "node ./scripts/checkCopyrightHeaders.js",
"clean-all": "rm -rf ./node_modules && rm -rf ./packages/*/node_modules && yarn clean-e2e && yarn build-clean",
"clean-e2e": "find ./e2e -not \\( -path ./e2e/presets/js -prune \\) -not \\( -path ./e2e/presets/json -prune \\) -mindepth 2 -type d \\( -name node_modules -prune \\) -exec rm -r '{}' +",
"jest": "node ./packages/jest-cli/bin/jest.js",
@@ -115,5 +117,8 @@
"type": "opencollective",
"url": "https://opencollective.com/jest",
"logo": "https://opencollective.com/jest/logo.txt"
+ },
+ "engines": {
+ "node": ">= 6"
}
}
diff --git a/packages/babel-jest/package.json b/packages/babel-jest/package.json
index 568f2fecfd0e..6cc0a5134faf 100644
--- a/packages/babel-jest/package.json
+++ b/packages/babel-jest/package.json
@@ -17,5 +17,8 @@
},
"peerDependencies": {
"@babel/core": "^7.0.0"
+ },
+ "engines": {
+ "node": ">= 6"
}
}
diff --git a/packages/babel-plugin-jest-hoist/package.json b/packages/babel-plugin-jest-hoist/package.json
index c7923258b175..22ddd76455b4 100644
--- a/packages/babel-plugin-jest-hoist/package.json
+++ b/packages/babel-plugin-jest-hoist/package.json
@@ -5,6 +5,9 @@
"type": "git",
"url": "https://github.com/facebook/jest.git"
},
+ "engines": {
+ "node": ">= 6"
+ },
"license": "MIT",
"main": "build/index.js"
}
diff --git a/packages/babel-preset-jest/package.json b/packages/babel-preset-jest/package.json
index ab7d750a9817..357ddc7029a4 100644
--- a/packages/babel-preset-jest/package.json
+++ b/packages/babel-preset-jest/package.json
@@ -10,5 +10,8 @@
"dependencies": {
"@babel/plugin-syntax-object-rest-spread": "^7.0.0",
"babel-plugin-jest-hoist": "^23.2.0"
+ },
+ "engines": {
+ "node": ">= 6"
}
}
diff --git a/packages/diff-sequences/package.json b/packages/diff-sequences/package.json
index d8d6a7afd7d7..1428313d9399 100644
--- a/packages/diff-sequences/package.json
+++ b/packages/diff-sequences/package.json
@@ -14,5 +14,8 @@
"callback",
"diff"
],
+ "engines": {
+ "node": ">= 6"
+ },
"main": "build/index.js"
}
diff --git a/packages/eslint-config-fb-strict/package.json b/packages/eslint-config-fb-strict/package.json
index 8aada90416df..8e9cb2d7e065 100644
--- a/packages/eslint-config-fb-strict/package.json
+++ b/packages/eslint-config-fb-strict/package.json
@@ -14,9 +14,12 @@
"eslint": "^4.2.0 || ^5.0.0",
"eslint-plugin-babel": "^5.0.0",
"eslint-plugin-flowtype": "^2.35.0",
- "eslint-plugin-jest": "^21.0.0",
+ "eslint-plugin-jest": "^21.0.0 || ^22.0.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.1.0",
"eslint-plugin-relay": "~0.0.8"
+ },
+ "engines": {
+ "node": ">= 6"
}
}
diff --git a/packages/expect/package.json b/packages/expect/package.json
index 8f488346b5b3..313df003904d 100644
--- a/packages/expect/package.json
+++ b/packages/expect/package.json
@@ -15,5 +15,8 @@
"jest-matcher-utils": "^23.6.0",
"jest-message-util": "^23.4.0",
"jest-regex-util": "^23.3.0"
+ },
+ "engines": {
+ "node": ">= 6"
}
}
diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap
index 400e8b6e424d..6e9c035453aa 100644
--- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap
+++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap
@@ -3479,6 +3479,30 @@ Received:
\\"bar\\">"
`;
+exports[`.toStrictEqual() matches the expected snapshot when it fails 1`] = `
+"expect(>received>).toStrictEqual(>expected>)>
+
+Difference:
+
+- Expected>
++ Received>
+
+ Object {>
+- \\"test\\": TestClassA {>
+- \\"a\\": 1,>
+- \\"b\\": 2,>
+- },>
++ \\"test\\": 2,>
+ }>"
+`;
+
+exports[`.toStrictEqual() matches the expected snapshot when it fails 2`] = `
+"expect(>received>).>not.toStrictEqual(>expected>)>
+
+Expected: {\\"test\\": {\\"a\\": 1, \\"b\\": 2}}>
+Received: {\\"test\\": {\\"a\\": 1, \\"b\\": 2}}>"
+`;
+
exports[`toMatchObject() {pass: false} expect([0]).toMatchObject([-0]) 1`] = `
"expect(>received>).toMatchObject(>expected>)>
@@ -3664,6 +3688,23 @@ Difference:
}>"
`;
+exports[`toMatchObject() {pass: false} expect({"a": "b"}).toMatchObject({"c": "d"}) 1`] = `
+"expect(>received>).toMatchObject(>expected>)>
+
+Expected value to match object:
+ {\\"c\\": \\"d\\"}>
+Received:
+ {\\"a\\": \\"b\\"}>
+Difference:
+- Expected>
++ Received>
+
+ Object {>
+- \\"c\\": \\"d\\",>
++ \\"a\\": \\"b\\",>
+ }>"
+`;
+
exports[`toMatchObject() {pass: false} expect({"a": [{"a": "a", "b": "b"}]}).toMatchObject({"a": [{"a": "c"}]}) 1`] = `
"expect(>received>).toMatchObject(>expected>)>
@@ -4002,6 +4043,15 @@ Received:
{\\"a\\": \\"b\\", \\"t\\": {\\"x\\": {\\"r\\": \\"r\\"}, \\"z\\": \\"z\\"}}>"
`;
+exports[`toMatchObject() {pass: true} expect({"a": "b"}).toMatchObject({"a": "b"}) 1`] = `
+"expect(>received>).not.toMatchObject(>expected>)>
+
+Expected value not to match object:
+ {\\"a\\": \\"b\\"}>
+Received:
+ {\\"a\\": \\"b\\"}>"
+`;
+
exports[`toMatchObject() {pass: true} expect({"a": [{"a": "a", "b": "b"}]}).toMatchObject({"a": [{"a": "a"}]}) 1`] = `
"expect(>received>).not.toMatchObject(>expected>)>
diff --git a/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/spyMatchers.test.js.snap
similarity index 94%
rename from packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap
rename to packages/expect/src/__tests__/__snapshots__/spyMatchers.test.js.snap
index 95a15e70ccf4..220a4e47e8de 100644
--- a/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap
+++ b/packages/expect/src/__tests__/__snapshots__/spyMatchers.test.js.snap
@@ -149,6 +149,14 @@ Expected mock function \\"named-mock\\" to have last returned:
But it was not called>"
`;
+exports[`lastReturnedWith incomplete recursive calls are handled properly 1`] = `
+"expect(>jest.fn()>).lastReturnedWith(>expected>)>
+
+Expected mock function to have last returned:
+ 0>
+But the last call has not returned yet>"
+`;
+
exports[`lastReturnedWith works only on spies or jest.fn 1`] = `
"expect(>jest.fn()>)[.not].lastReturnedWith(>)>
@@ -237,6 +245,15 @@ But the last call returned:
\\"foo\\">"
`;
+exports[`lastReturnedWith works with three calls 1`] = `
+"expect(>jest.fn()>).not.lastReturnedWith(>expected>)>
+
+Expected mock function to not have last returned:
+ \\"foo3\\">
+But it last returned exactly:
+ \\"foo3\\">"
+`;
+
exports[`lastReturnedWith works with undefined 1`] = `
"expect(>jest.fn()>).not.lastReturnedWith(>expected>)>
@@ -406,6 +423,40 @@ Expected mock function \\"named-mock\\" first call to have returned with:
But it was not called>"
`;
+exports[`nthReturnedWith incomplete recursive calls are handled properly 1`] = `
+"expect(>jest.fn()>).nthReturnedWith(>expected>)>
+
+Expected mock function first call to have returned with:
+ 6>
+But the first call has not returned yet>"
+`;
+
+exports[`nthReturnedWith incomplete recursive calls are handled properly 2`] = `
+"expect(>jest.fn()>).nthReturnedWith(>expected>)>
+
+Expected mock function second call to have returned with:
+ 3>
+But the second call has not returned yet>"
+`;
+
+exports[`nthReturnedWith incomplete recursive calls are handled properly 3`] = `
+"expect(>jest.fn()>).not.nthReturnedWith(>expected>)>
+
+Expected mock function third call to not have returned with:
+ 1>
+But the third call returned exactly:
+ 1>"
+`;
+
+exports[`nthReturnedWith incomplete recursive calls are handled properly 4`] = `
+"expect(>jest.fn()>).not.nthReturnedWith(>expected>)>
+
+Expected mock function 4th call to not have returned with:
+ 0>
+But the 4th call returned exactly:
+ 0>"
+`;
+
exports[`nthReturnedWith should reject non integer nth value 1`] = `"nth value 0.1> must be a positive integer greater than 0>"`;
exports[`nthReturnedWith should reject nth value greater than number of calls 1`] = `
@@ -1437,6 +1488,14 @@ Expected mock function \\"named-mock\\" to have last returned:
But it was not called>"
`;
+exports[`toHaveLastReturnedWith incomplete recursive calls are handled properly 1`] = `
+"expect(>jest.fn()>).toHaveLastReturnedWith(>expected>)>
+
+Expected mock function to have last returned:
+ 0>
+But the last call has not returned yet>"
+`;
+
exports[`toHaveLastReturnedWith works only on spies or jest.fn 1`] = `
"expect(>jest.fn()>)[.not].toHaveLastReturnedWith(>)>
@@ -1525,6 +1584,15 @@ But the last call returned:
\\"foo\\">"
`;
+exports[`toHaveLastReturnedWith works with three calls 1`] = `
+"expect(>jest.fn()>).not.toHaveLastReturnedWith(>expected>)>
+
+Expected mock function to not have last returned:
+ \\"foo3\\">
+But it last returned exactly:
+ \\"foo3\\">"
+`;
+
exports[`toHaveLastReturnedWith works with undefined 1`] = `
"expect(>jest.fn()>).not.toHaveLastReturnedWith(>expected>)>
@@ -1558,6 +1626,40 @@ Expected mock function \\"named-mock\\" first call to have returned with:
But it was not called>"
`;
+exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 1`] = `
+"expect(>jest.fn()>).toHaveNthReturnedWith(>expected>)>
+
+Expected mock function first call to have returned with:
+ 6>
+But the first call has not returned yet>"
+`;
+
+exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 2`] = `
+"expect(>jest.fn()>).toHaveNthReturnedWith(>expected>)>
+
+Expected mock function second call to have returned with:
+ 3>
+But the second call has not returned yet>"
+`;
+
+exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 3`] = `
+"expect(>jest.fn()>).not.toHaveNthReturnedWith(>expected>)>
+
+Expected mock function third call to not have returned with:
+ 1>
+But the third call returned exactly:
+ 1>"
+`;
+
+exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 4`] = `
+"expect(>jest.fn()>).not.toHaveNthReturnedWith(>expected>)>
+
+Expected mock function 4th call to not have returned with:
+ 0>
+But the 4th call returned exactly:
+ 0>"
+`;
+
exports[`toHaveNthReturnedWith should reject non integer nth value 1`] = `"nth value 0.1> must be a positive integer greater than 0>"`;
exports[`toHaveNthReturnedWith should reject nth value greater than number of calls 1`] = `
@@ -1735,6 +1837,12 @@ Expected mock function \\"named-mock\\" not to have returned, but it returned:
42>"
`;
+exports[`toHaveReturned incomplete recursive calls are handled properly 1`] = `
+"expect(>jest.fn()>).toHaveReturned(>)>
+
+Expected mock function to have returned."
+`;
+
exports[`toHaveReturned passes when at least one call does not throw 1`] = `
"expect(>jest.fn()>).not.toHaveReturned(>)>
@@ -1850,6 +1958,12 @@ exports[`toHaveReturnedTimes includes the custom mock name in the error message
Expected mock function \\"named-mock\\" to have returned one time>, but it returned two times>."
`;
+exports[`toHaveReturnedTimes incomplete recursive calls are handled properly 1`] = `
+"expect(>jest.fn()>).not.toHaveReturnedTimes(>2>)>
+
+Expected mock function not to have returned two times>, but it returned exactly two times>."
+`;
+
exports[`toHaveReturnedTimes only accepts a number argument 1`] = `
"expect(>received>)[.not].toHaveReturnedTimes(>expected>)>
@@ -1936,6 +2050,14 @@ Expected mock function \\"named-mock\\" to have returned:
But it did not return>."
`;
+exports[`toHaveReturnedWith incomplete recursive calls are handled properly 1`] = `
+"expect(>jest.fn()>).toHaveReturnedWith(>expected>)>
+
+Expected mock function to have returned:
+ undefined>
+But it did not return>."
+`;
+
exports[`toHaveReturnedWith works only on spies or jest.fn 1`] = `
"expect(>jest.fn()>)[.not].toHaveReturnedWith(>)>
@@ -2093,6 +2215,12 @@ Expected mock function \\"named-mock\\" not to have returned, but it returned:
42>"
`;
+exports[`toReturn incomplete recursive calls are handled properly 1`] = `
+"expect(>jest.fn()>).toReturn(>)>
+
+Expected mock function to have returned."
+`;
+
exports[`toReturn passes when at least one call does not throw 1`] = `
"expect(>jest.fn()>).not.toReturn(>)>
@@ -2208,6 +2336,12 @@ exports[`toReturnTimes includes the custom mock name in the error message 1`] =
Expected mock function \\"named-mock\\" to have returned one time>, but it returned two times>."
`;
+exports[`toReturnTimes incomplete recursive calls are handled properly 1`] = `
+"expect(>jest.fn()>).not.toReturnTimes(>2>)>
+
+Expected mock function not to have returned two times>, but it returned exactly two times>."
+`;
+
exports[`toReturnTimes only accepts a number argument 1`] = `
"expect(>received>)[.not].toReturnTimes(>