@@ -177,6 +177,10 @@ Jest `moduleDirectories` option.
177
177
This will make all the ` .js ` files in the test-utils directory importable
178
178
without ` ../ ` .
179
179
180
+ > ** Note**
181
+ >
182
+ > This can't be used with Create React App.
183
+
180
184
``` diff title="my-component.test.js"
181
185
- import { render, fireEvent } from '../test-utils';
182
186
+ import { render, fireEvent } from 'test-utils';
@@ -194,45 +198,20 @@ module.exports = {
194
198
}
195
199
```
196
200
197
- _ Typescript config needs to be updated as follow:_
201
+ If you're using TypeScript, merge this into your ` tsconfig.json ` . If you're
202
+ using Create React App without TypeScript, save this to ` jsconfig.json ` instead.
198
203
199
204
``` diff title="tsconfig.json"
200
205
{
201
206
"compilerOptions": {
202
- // ...,
203
- + "baseUrl": "src",
204
- + "paths": {
205
- + "test-utils": ["./utils/test-utils"]
206
- + }
207
+ "baseUrl": "src",
208
+ "paths": {
209
+ "test-utils": ["./utils/test-utils"]
210
+ }
207
211
}
208
212
}
209
213
```
210
214
211
- ### Jest and Create React App
212
-
213
- If your project is based on top of Create React App, to make the ` test-utils `
214
- file accessible without using relative imports, you just need to create a ` .env `
215
- file in the root of your project with the following configuration:
216
-
217
- ```
218
- // Create React App project structure
219
-
220
- $ app
221
- .
222
- ├── .env
223
- ├── src
224
- │ ├── utils
225
- │ │ └── test-utils.js
226
- │
227
- ```
228
-
229
- ```
230
- // .env
231
-
232
- // example if your utils folder is inside the /src directory.
233
- NODE_PATH=src/utils
234
- ```
235
-
236
215
### Jest 24 (or lower) and defaults
237
216
238
217
If you're using the Jest testing framework version 24 or lower with the default
0 commit comments