Skip to content

Commit 223fa49

Browse files
committed
[Doc] Explain how to set up Jest for RA 5.13
1 parent aeeb21d commit 223fa49

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

docs/UnitTesting.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,19 @@ describe('UserShow', () => {
224224
});
225225
});
226226
```
227+
228+
## Working with Jest
229+
230+
**Tip:** In general, we recommend using [Vitest](https://vitest.dev/) for testing React-admin applications, as it is faster and more modern than Jest. In particular, it is compatible out of the box with ESM and TypeScript, whereas Jest requires additional and experimental configuration for that. If, however, you are already using Jest, here are some tips to make it work smoothly with React-admin.
231+
232+
Starting with version [5.13.0](https://github.com/marmelab/react-admin/pull/10995), React-admin changed the way it exports its modules to be fully compatible with ESM.
233+
234+
- If you are using Jest in CJS mode (default), you will need to add the following configuration to your `jest.config.js` file to make sure React-admin packages are properly transformed:
235+
236+
```diff
237+
-transformIgnorePatterns: ['node_modules/(?!(@hookform|react-hotkeys-hook))']
238+
+transformIgnorePatterns: ['node_modules/(?!(@hookform|react-hotkeys-hook|react-admin|ra-core|ra-ui-materialui|ra-input-rich-text|ra-i18n-polyglot|ra-data-fakerest|ra-language-english))']
239+
```
240+
241+
- If you are using Jest in ESM mode, then the React-admin packages should work without any further configuration. You shouldn't need `transformIgnorePatterns` at all.
242+

docs_headless/src/content/docs/UnitTesting.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,21 @@ describe('UserShow', () => {
222222
});
223223
});
224224
```
225+
226+
## Working with Jest
227+
228+
:::tip
229+
In general, we recommend using [Vitest](https://vitest.dev/) for testing ra-core applications, as it is faster and more modern than Jest. In particular, it is compatible out of the box with ESM and TypeScript, whereas Jest requires additional and experimental configuration for that. If, however, you are already using Jest, here are some tips to make it work smoothly with ra-core.
230+
:::
231+
232+
Starting with version [5.13.0](https://github.com/marmelab/react-admin/pull/10995), ra-core changed the way it exports its modules to be fully compatible with ESM.
233+
234+
- If you are using Jest in CJS mode (default), you will need to add the following configuration to your `jest.config.js` file to make sure ra-core is properly transformed:
235+
236+
```diff
237+
-transformIgnorePatterns: ['node_modules/(?!(@hookform|react-hotkeys-hook))']
238+
+transformIgnorePatterns: ['node_modules/(?!(@hookform|react-hotkeys-hook|ra-core|ra-i18n-polyglot|ra-data-fakerest|ra-language-english))']
239+
```
240+
241+
- If you are using Jest in ESM mode, then the ra-core packages should work without any further configuration. You shouldn't need `transformIgnorePatterns` at all.
242+

0 commit comments

Comments
 (0)