You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you do not already have babel configured for your project, you can use Babel to target your current version of Node by creating a `babel.config.js` file in the root of your project:
133
+
Configure Babel to target your current version of Node by creating a `babel.config.js` file in the root of your project:
134
134
135
135
```javascript
136
136
// babel.config.js
@@ -176,7 +176,7 @@ Jest can be used in projects that use [webpack](https://webpack.js.org/) to mana
176
176
177
177
### Using parcel
178
178
179
-
Jest can be used in projects that use [parcel-bundler](https://parceljs.org/) to manage assets, styles, and compilation similar to webpack. Parcel requires zero configuration.
179
+
Jest can be used in projects that use [parcel-bundler](https://parceljs.org/) to manage assets, styles, and compilation similar to webpack. Parcel requires zero configuration. Refer to the official [docs](https://parceljs.org/getting_started.html) to get started.
180
180
181
181
### Using TypeScript
182
182
@@ -198,7 +198,7 @@ module.exports = {
198
198
};
199
199
```
200
200
201
-
Note, there are some [caveats](https://babeljs.io/docs/en/next/babel-plugin-transform-typescript.html#caveats) to using TypeScript with Babel. Because TypeScript support in Babel is transpilation, Jest will not type-check your tests as they are run. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
201
+
However, there are some [caveats](https://babeljs.io/docs/en/babel-plugin-transform-typescript#caveats) to using TypeScript with Babel. Because TypeScript support in Babel is transpilation, Jest will not type-check your tests as they are run. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
Copy file name to clipboardexpand all lines: docs/CLI.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -126,7 +126,7 @@ Runs tests related to the current changes and the changes made in the last commi
126
126
127
127
### `--changedSince`
128
128
129
-
Runs tests related to the changes since the provided branch. If the current branch has diverged from the given branch, then only changes made locally will be tested. Behaves similarly to `--onlyChanged`.
129
+
Runs tests related to the changes since the provided branch or commit hash. If the current branch has diverged from the given branch, then only changes made locally will be tested. Behaves similarly to `--onlyChanged`.
Copy file name to clipboardexpand all lines: docs/Configuration.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -151,7 +151,7 @@ Automatically clear mock calls and instances before every test. Equivalent to ca
151
151
152
152
Default: `false`
153
153
154
-
Indicates whether the coverage information should be collected while executing the test. Because these retrofits all executed files with coverage collection statements, it may significantly slow down your tests.
154
+
Indicates whether the coverage information should be collected while executing the test. Because this retrofits all executed files with coverage collection statements, it may significantly slow down your tests.
155
155
156
156
### `collectCoverageFrom`[array]
157
157
@@ -989,7 +989,7 @@ You can create your own module that will be used for setting up the test environ
989
989
990
990
The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/master/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases.
991
991
992
-
Any docblock pragmas in test files will be passed to the environment constructor and can be used for per-test configuration. If the pragma does not have a value, it will be present in the object with it's value set to an empty string. If the pragma is not present, it will not be present in the object.
992
+
Any docblock pragmas in test files will be passed to the environment constructor and can be used for per-test configuration. If the pragma does not have a value, it will be present in the object with its value set to an empty string. If the pragma is not present, it will not be present in the object.
993
993
994
994
_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
Copy file name to clipboardexpand all lines: docs/ExpectAPI.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ For additional Jest matchers maintained by the Jest Community check out [`jest-e
17
17
18
18
### `expect(value)`
19
19
20
-
The `expect` function is used every time you want to test a value. You will rarely call `expect` by itself. Instead, you will use `expect` along with a "matcher" function to assert something about value.
20
+
The `expect` function is used every time you want to test a value. You will rarely call `expect` by itself. Instead, you will use `expect` along with a "matcher" function to assert something about a value.
21
21
22
22
It's easier to understand this with an example. Let's say you have a method `bestLaCroixFlavor()` which is supposed to return the string `'grapefruit'`. Here's how you would test that:
**The ideal configuration for Babel will depend on your project.** See [Babel's docs](https://babeljs.io/docs/en/) for more details.
99
+
_The ideal configuration for Babel will depend on your project._ See [Babel's docs](https://babeljs.io/docs/en/) for more details.
109
100
110
101
<details><summarymarkdown="span"><strong>Making your Babel config jest-aware</strong></summary>
111
102
@@ -179,4 +170,4 @@ module.exports = {
179
170
};
180
171
```
181
172
182
-
However, there are some [caveats](https://babeljs.io/docs/en/next/babel-plugin-transform-typescript.html#caveats) to using TypeScript with Babel. Because TypeScript support in Babel is transpilation, Jest will not type-check your tests as they are run. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
173
+
However, there are some [caveats](https://babeljs.io/docs/en/babel-plugin-transform-typescript#caveats) to using TypeScript with Babel. Because TypeScript support in Babel is transpilation, Jest will not type-check your tests as they are run. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/master/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in this case, it's `<Link>` component) that should be fixed, or the implementation has changed and the snapshot needs to be updated.
42
+
The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/master/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in the `<Link>` component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated.
43
43
44
-
> Note: The snapshot is directly scoped to the data you render – in our example it's`<Link />` component with page prop passed to it. This implies that even if any other file has missing props (Say, `App.js`) in the `<Link />` component, it will still pass the test as the test doesn't know the usage of `<Link />` component and it's scoped only to the `Link.react.js`. Also, Rendering the same component with different props in other snapshot tests will not affect the first one, as the tests don't know about each other.
44
+
> Note: The snapshot is directly scoped to the data you render – in our example the`<Link />` component with `page` prop passed to it. This implies that even if any other file has missing props (Say, `App.js`) in the `<Link />` component, it will still pass the test as the test doesn't know the usage of `<Link />` component and it's scoped only to the `Link.react.js`. Also, Rendering the same component with different props in other snapshot tests will not affect the first one, as the tests don't know about each other.
45
45
46
46
More information on how snapshot testing works and why we built it can be found on the [release blog post](https://jestjs.io/blog/2016/07/27/jest-14.html). We recommend reading [this blog post](http://benmccormick.org/2016/09/19/testing-with-jest-snapshots-first-impressions/) to get a good sense of when you should use snapshot testing. We also recommend watching this [egghead video](https://egghead.io/lessons/javascript-use-jest-s-snapshot-testing-feature?pl=testing-javascript-with-jest-a36c4074) on Snapshot Testing with Jest.
Copy file name to clipboardexpand all lines: website/versioned_docs/version-22.x/CLI.md
+17-5
Original file line number
Diff line number
Diff line change
@@ -134,9 +134,9 @@ Forces test results output highlighting even if stdout is not a TTY.
134
134
135
135
Alias: `-c`. The path to a Jest config file specifying how to find and execute tests. If no `rootDir` is set in the config, the directory containing the config file is assumed to be the `rootDir` for the project. This can also be a JSON-encoded value which Jest will use as configuration.
136
136
137
-
### `--coverage`
137
+
### `--coverage[=<boolean>]`
138
138
139
-
Indicates that test coverage information should be collected and reported in the output.
139
+
Alias: `--collectCoverage`. Indicates that test coverage information should be collected and reported in the output. Optionally pass `<boolean>` to override option set in configuration.
140
140
141
141
### `--debug`
142
142
@@ -202,9 +202,15 @@ Alias: `-o`. Attempts to identify which tests to run based on which files have c
202
202
203
203
Allows the test suite to pass when no files are found.
204
204
205
-
### `--projects <project1> ... <projectN>`
205
+
### `--projects <path1> ... <pathN>`
206
206
207
-
Run tests from one or more projects.
207
+
Run tests from one or more projects, found in the specified paths; also takes path globs. This option is the CLI equivalent of the [`projects`](configuration#projects-arraystring--projectconfig) configuration option. Note that if configuration files are found in the specified paths, _all_ projects specified within those configuration files will be run.
208
+
209
+
### `--reporters`
210
+
211
+
Run tests with specified reporters. Run tests with specified reporters. Example with multiple reporters:
@@ -230,7 +236,9 @@ Prevent tests from printing messages through the console.
230
236
231
237
### `--testNamePattern=<regex>`
232
238
233
-
Alias: `-t`. Run only tests and test suites with a name that matches the regex. For example, suppose you want to run only tests related to authorization which will have names like `"GET /api/posts with auth"`, then you can use `jest -t=auth`.
239
+
Alias: `-t`. Run only tests with a name that matches the regex. For example, suppose you want to run only tests related to authorization which will have names like `"GET /api/posts with auth"`, then you can use `jest -t=auth`.
240
+
241
+
_Note: The regex is matched against the full name, which is a combination of the test name and all its surrounding describe blocks._
234
242
235
243
### `--testLocationInResults`
236
244
@@ -249,6 +257,10 @@ Note that `column` is 0-indexed while `line` is not.
249
257
250
258
A regexp pattern string that is matched against all tests paths before executing the test. On Windows, you will need to use `/` as a path separator or escape `\` as `\\`.
251
259
260
+
### `--testPathIgnorePatterns=[array]`
261
+
262
+
An array of regexp pattern strings that are tested against all tests paths before executing the test. Contrary to `--testPathPattern`, it will only run those tests with a path that does not match with the provided regexp expressions.
0 commit comments