Skip to content

Commit 27fc2ac

Browse files
committed
Update README.md
1 parent 4bcfe19 commit 27fc2ac

File tree

1 file changed

+68
-44
lines changed

1 file changed

+68
-44
lines changed

README.md

Lines changed: 68 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@
55

66
🃏 Delightful JavaScript Testing
77

8-
- **👩🏻‍💻 Easy Setup**: Jest is a complete and easy to set up 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.
99

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.
1111

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.
1313

1414
## Getting Started
1515

1616
<!-- generated_getting_started_start -->
17-
Install Jest using `npm`:
17+
18+
Install Jest using [`npm`](https://www.npmjs.com/):
1819

1920
```
2021
npm install --save-dev jest
2122
```
2223

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:
2432

2533
```javascript
2634
function sum(a, b) {
@@ -58,33 +66,51 @@ PASS ./sum.test.js
5866

5967
**You just successfully wrote your first test using Jest!**
6068

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).
6272

6373
## Running from command line
6474

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.
6677

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:
6880

6981
```bash
7082
jest my-test --notify --config=config.json
7183
```
7284

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.
7487

7588
## Additional Configuration
7689

7790
### Using Babel
7891

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:
8094

8195
```
82-
npm install --save-dev jest babel-jest regenerator-runtime
96+
npm install --save-dev babel-jest babel-core regenerator-runtime
8397
```
8498

85-
*Note: Explicitly installing `regenerator-runtime` is not needed if you use `npm` 3 or 4 or Yarn*
99+
> Note: If you are using a babel version 7 then you need to install `babel-jest`
100+
> with the following command:
101+
>
102+
> ```
103+
> npm install --save-dev babel-jest 'babel-core@^7.0.0-0' @babel/core regenerator-runtime
104+
> ```
105+
106+
_Note: Explicitly installing `regenerator-runtime` is not needed if you use
107+
`npm` 3 or 4 or Yarn_
86108
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
113+
[`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:
88114
89115
```json
90116
{
@@ -94,11 +120,30 @@ Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file
94120
95121
You are now set up to use all ES6 features and React specific syntax.
96122

97-
> Note: If you are using a more complicated Babel configuration, using Babel's `env` option,
98-
keep in mind that Jest will automatically define `NODE_ENV` as `test`.
99-
It will not use `development` section like Babel does by default when no `NODE_ENV` is set.
123+
> Note: If you are using a more complicated Babel configuration, using Babel's
124+
> `env` option, keep in mind that Jest will automatically define `NODE_ENV` as
125+
> `test`. It will not use `development` section like Babel does by default when
126+
> no `NODE_ENV` is set.
127+
128+
> Note: If you've turned off transpilation of ES2015 modules with the option
129+
> `{ "modules": false }`, you have to make sure to turn this on in your test
130+
> environment.
131+
132+
```json
133+
{
134+
"presets": [["es2015", {"modules": false}], "react"],
135+
"env": {
136+
"test": {
137+
"presets": [["es2015"], "react"]
138+
}
139+
}
140+
}
141+
```
100142

101-
> 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:
102147
103148
```json
104149
// package.json
@@ -111,36 +156,15 @@ It will not use `development` section like Babel does by default when no `NODE_E
111156

112157
### Using webpack
113158

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.
115163

116164
### Using TypeScript
117165

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:
125-
126-
```json
127-
{
128-
"jest": {
129-
"transform": {
130-
"^.+\\.tsx?$": "ts-jest"
131-
},
132-
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
133-
"moduleFileExtensions": [
134-
"ts",
135-
"tsx",
136-
"js",
137-
"jsx",
138-
"json",
139-
"node"
140-
]
141-
}
142-
}
143-
```
166+
To use TypeScript in your tests you can use
167+
[ts-jest](https://github.com/kulshekhar/ts-jest).
144168
<!-- generated_getting_started_end -->
145169

146170
## Documentation

0 commit comments

Comments
 (0)