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
<ahref="https://twitter.com/intent/follow?screen_name=fbjest"><imgalign="right"src="https://img.shields.io/twitter/follow/fbjest.svg?style=social&label=Follow%20@fbjest"alt="Follow on Twitter"></a>
26
4
</p>
27
5
28
-
**👩🏻💻 Developer Ready**: Complete and ready to set-up JavaScript testing solution. Works out of the box for any React project.
Configure Babel to target your current version of Node by creating a `babel.config.js` file in the root of your project:
106
+
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:
**The ideal configuration for Babel will depend on your project.** See [Babel's docs](https://babeljs.io/docs/en/) for more details.
115
+
_The ideal configuration for Babel will depend on your project._ See [Babel's docs](https://babeljs.io/docs/en/) for more details.
116
+
117
+
<details><summarymarkdown="span"><strong>Making your Babel config jest-aware</strong></summary>
141
118
142
119
Jest will set `process.env.NODE_ENV` to `'test'` if it's not set to something else. You can use that in your configuration to conditionally setup only the compilation needed for Jest, e.g.
143
120
@@ -162,30 +139,35 @@ module.exports = {
162
139
};
163
140
```
164
141
165
-
#### Babel 6
166
-
167
-
Jest 24 dropped support for Babel 6. We highly recommend you to upgrade to Babel 7, which is actively maintained. However, if you cannot upgrade to Babel 7, either keep using Jest 23 or upgrade to Jest 24 with `babel-jest` locked at version 23, like in the example below:
168
-
169
-
```
170
-
"dependencies": {
171
-
"babel-core": "^6.26.3",
172
-
"babel-jest": "^23.6.0",
173
-
"babel-preset-env": "^1.7.0",
174
-
"jest": "^24.0.0"
175
-
}
176
-
```
142
+
</details>
177
143
178
-
While we generally recommend using the same version of every Jest package, this workaround will allow you to continue using the latest version of Jest with Babel 6 for now.
144
+
<!-- Note that the Babel 6 section in the Getting Started was removed -->
179
145
180
146
### Using webpack
181
147
182
148
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://jestjs.io/docs/en/webpack) to get started.
183
149
184
150
### Using TypeScript
185
151
186
-
Jest supports TypeScript out of the box, via Babel.
152
+
Jest supports TypeScript, via Babel. First make sure you followed the instructions on [using Babel](#using-babel) above. Next install the `@babel/preset-typescript` via `yarn`:
153
+
154
+
```bash
155
+
yarn add --dev @babel/preset-typescript
156
+
```
157
+
158
+
Then add `@babel/preset-typescript` to the list of presets in your `babel.config.js`.
However, there are some caveats to using Typescript with Babel, see http://artsy.github.io/blog/2017/11/27/Babel-7-and-TypeScript/. Another caveat is that Jest will not typecheck your tests. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
170
+
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 just transpilation, Jest will not type-check your tests as they are ran. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
189
171
190
172
<!-- end copied -->
191
173
@@ -200,7 +182,7 @@ Learn more about using [Jest on the official site!](https://jestjs.io)
200
182
201
183
## Badge
202
184
203
-
Show the world you're using _Jest_→[](https://github.com/facebook/jest)[](https://github.com/facebook/jest)
185
+
Show the world you're using _Jest_`→`[](https://github.com/facebook/jest)[](https://github.com/facebook/jest)
204
186
205
187
```md
206
188
[](https://github.com/facebook/jest) [](https://github.com/facebook/jest)
Copy file name to clipboardExpand all lines: docs/GettingStarted.md
+10-4
Original file line number
Diff line number
Diff line change
@@ -107,6 +107,8 @@ module.exports = {
107
107
108
108
**The ideal configuration for Babel will depend on your project.** See [Babel's docs](https://babeljs.io/docs/en/) for more details.
109
109
110
+
<details><summarymarkdown="span"><strong>Making your Babel config jest-aware</strong></summary>
111
+
110
112
Jest will set `process.env.NODE_ENV` to `'test'` if it's not set to something else. You can use that in your configuration to conditionally setup only the compilation needed for Jest, e.g.
Jest 24 dropped support for Babel 6. We highly recommend you to upgrade to Babel 7, which is actively maintained. However, if you cannot upgrade to Babel 7, either keep using Jest 23 or upgrade to Jest 24 with `babel-jest` locked at version 23, like in the example below:
136
140
@@ -145,6 +149,8 @@ Jest 24 dropped support for Babel 6. We highly recommend you to upgrade to Babel
145
149
146
150
While we generally recommend using the same version of every Jest package, this workaround will allow you to continue using the latest version of Jest with Babel 6 for now.
147
151
152
+
</details>
153
+
148
154
### Using webpack
149
155
150
156
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](Webpack.md) to get started.
Note that there are some caveats to using Typescript with Babel, see http://artsy.github.io/blog/2017/11/27/Babel-7-and-TypeScript/. Another caveat is that Jest will not typecheck your tests. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
178
+
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 just transpilation, Jest will not type-check your tests as they are ran. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
0 commit comments