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
Copy file name to clipboardExpand all lines: README.md
+68-44Lines changed: 68 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,22 +5,30 @@
5
5
6
6
🃏 Delightful JavaScript Testing
7
7
8
-
-**👩🏻💻 Easy Setup**: Jest is a complete and easy to setup JavaScript testing solution. In fact, Jest works out of the box for any React project.
8
+
-**👩🏻💻 Easy Setup**: Complete and easy to set-up JavaScript testing solution. Works out of the box for any React project.
9
9
10
-
-**🏃🏽 Instant Feedback**: Failed tests run first. Fast interactive mode can switch between running all tests or only test files related to changed files.
10
+
-**🏃🏽 Instant Feedback**: Fast interactive watch mode runs only test files related to changed files and is optimized to give signal quickly.
11
11
12
-
-**📸 Snapshot Testing**: Jest can [capture snapshots](http://facebook.github.io/jest/docs/en/snapshot-testing.html) of React trees or other serializable values to simplify testing.
12
+
-**📸 Snapshot Testing**: Capture snapshots of React trees or other serializable values to simplify testing and to analyze how state changes over time.
13
13
14
14
## Getting Started
15
15
16
16
<!-- generated_getting_started_start -->
17
-
Install Jest using `npm`:
17
+
18
+
Install Jest using [`npm`](https://www.npmjs.com/):
18
19
19
20
```
20
21
npm install --save-dev jest
21
22
```
22
23
23
-
Let's get started by writing a test for a hypothetical function that adds two numbers. First, create a `sum.js` file:
24
+
Or via [`yarn`](https://yarnpkg.com/en/package/jest):
25
+
26
+
```
27
+
yarn add --dev jest
28
+
```
29
+
30
+
Let's get started by writing a test for a hypothetical function that adds two
31
+
numbers. First, create a `sum.js` file:
24
32
25
33
```javascript
26
34
functionsum(a, b) {
@@ -58,33 +66,51 @@ PASS ./sum.test.js
58
66
59
67
**You just successfully wrote your first test using Jest!**
60
68
61
-
This test used `expect` and `toBe` to test that two values were exactly identical. To learn about the other things that Jest can test, see [Using Matchers](https://facebook.github.io/jest/docs/en/using-matchers.html).
69
+
This test used `expect` and `toBe` to test that two values were exactly
70
+
identical. To learn about the other things that Jest can test, see
71
+
[Using Matchers](UsingMatchers.md).
62
72
63
73
## Running from command line
64
74
65
-
You can run Jest directly from the CLI (if it's globally available in your `PATH`, e.g. by `npm install -g jest`) with variety of useful options.
75
+
You can run Jest directly from the CLI (if it's globally available in your
76
+
`PATH`, e.g. by `npm install -g jest`) with variety of useful options.
66
77
67
-
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:
78
+
Here's how to run Jest on files matching `my-test`, using `config.json` as a
79
+
configuration file and display a native OS notification after the run:
68
80
69
81
```bash
70
82
jest my-test --notify --config=config.json
71
83
```
72
84
73
-
If you'd like to learn more about running `jest` through the command line, take a look at the [Jest CLI Options](https://facebook.github.io/jest/docs/en/cli.html) page.
85
+
If you'd like to learn more about running `jest` through the command line, take
86
+
a look at the [Jest CLI Options](CLI.md) page.
74
87
75
88
## Additional Configuration
76
89
77
90
### Using Babel
78
91
79
-
To use [Babel](http://babeljs.io/), install the `babel-jest` and `regenerator-runtime` packages:
92
+
To use [Babel](http://babeljs.io/), install the `babel-jest` and
93
+
`regenerator-runtime` packages:
80
94
81
95
```
82
-
npm install --save-dev jest babel-jest regenerator-runtime
_Note: Explicitly installing `regenerator-runtime` is not needed if you use
107
+
`npm` 3 or 4 or Yarn_
86
108
87
-
Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file in your project's root folder. For example, if you are using ES6 and [React.js](https://facebook.github.io/react/) with the [`babel-preset-es2015`](https://babeljs.io/docs/plugins/preset-es2015/) and [`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:
109
+
Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file
110
+
in your project's root folder. For example, if you are using ES6 and
111
+
[React.js](https://facebook.github.io/react/) with the
112
+
[`babel-preset-es2015`](https://babeljs.io/docs/plugins/preset-es2015/) and
> Note: `babel-jest` is automatically installed when installing Jest and will automatically transform files if a babel configuration exists in your project. To avoid this behavior, you can explicitly reset the `transform` configuration option:
143
+
> Note: `babel-jest` is automatically installed when installing Jest and will
144
+
> automatically transform files if a babel configuration exists in your project.
145
+
> To avoid this behavior, you can explicitly reset the `transform` configuration
146
+
> option:
102
147
103
148
```json
104
149
// package.json
@@ -111,36 +156,15 @@ It will not use `development` section like Babel does by default when no `NODE_E
111
156
112
157
### Using webpack
113
158
114
-
Jest can be used in projects that use [webpack](https://webpack.github.io/) to manage assets, styles, and compilation. webpack does offer some unique challenges over other tools. Refer to the [webpack guide](https://facebook.github.io/jest/docs/en/webpack.html) to get started.
159
+
Jest can be used in projects that use [webpack](https://webpack.github.io/) to
160
+
manage assets, styles, and compilation. webpack does offer some unique
161
+
challenges over other tools. Refer to the [webpack guide](Webpack.md) to get
162
+
started.
115
163
116
164
### Using TypeScript
117
165
118
-
To use TypeScript in your tests, install the `ts-jest` package and the types for Jest.
119
-
120
-
```
121
-
npm install --save-dev jest ts-jest @types/jest
122
-
```
123
-
124
-
then modify your `package.json` so the `jest` section looks something like:
0 commit comments