Skip to content

Commit 8aedeac

Browse files
committed
Use tsconfig/jsconfig paths instead of NODE_PATH (#701)
* Use tsconfig/jsconfig paths instead of NODE_PATH * Bold text * Use a standalone note quote
1 parent 34ac9aa commit 8aedeac

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

docs/react-testing-library/setup.mdx

+10-31
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ Jest `moduleDirectories` option.
177177
This will make all the `.js` files in the test-utils directory importable
178178
without `../`.
179179

180+
> **Note**
181+
>
182+
> This can't be used with Create React App.
183+
180184
```diff title="my-component.test.js"
181185
- import { render, fireEvent } from '../test-utils';
182186
+ import { render, fireEvent } from 'test-utils';
@@ -194,45 +198,20 @@ module.exports = {
194198
}
195199
```
196200

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

199204
```diff title="tsconfig.json"
200205
{
201206
"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+
}
207211
}
208212
}
209213
```
210214

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-
236215
### Jest 24 (or lower) and defaults
237216

238217
If you're using the Jest testing framework version 24 or lower with the default

0 commit comments

Comments
 (0)