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
Copy file name to clipboardExpand all lines: docs/user/config/index.md
+25-5Lines changed: 25 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,28 @@ The later is preferred since it's more customizable, but it depends on your need
6
6
7
7
## Jest preset
8
8
9
+
### The 3 presets
10
+
11
+
`ts-jest` comes with 3 presets, covering most of project's base configuration:
12
+
13
+
| Preset name | Description |
14
+
|---|---|
15
+
|`ts-jest/presets/default`<br>or `ts-jest`|`ts-jest` will take care of `.ts` and `.tsx` files only, leaving JavaScript files as-is. |
16
+
|`ts-jest/presets/js-with-ts`| TypeScript and JavaScript file (`.ts`, `.tsx`, `.js` and `.jsx`) will be handled by `ts-jest`.<br>You'll need to set `allowJs` to `true` in your `tsconfig.json` file. |
17
+
|`ts-jest/presets/js-with-babel`| TypeScript files will be handled by `ts-jest`, and JavaScript files will be handled by `babel-jest`. |
18
+
9
19
### Basic usage
10
20
11
-
In most cases, simply adding `preset: 'ts-jest'` to your Jest config should be enough to start using TypeScript with Jest (assuming you did add `ts-jest` to your dev. dependencies of course):
21
+
In most cases, simply setting the `preset` key to the desired preset name in your Jest config should be enough to start using TypeScript with Jest (assuming you did add `ts-jest` to your dev. dependencies of course):
// Replace `ts-jest` with the preset you want to use
30
+
// from the above list
19
31
preset:'ts-jest'
20
32
};
21
33
```
@@ -27,27 +39,35 @@ module.exports = {
27
39
{
28
40
// [...]
29
41
"jest": {
42
+
// Replace `ts-jest` with the preset you want to use
43
+
// from the above list
30
44
"preset":"ts-jest"
31
45
}
32
46
}
33
47
```
34
48
35
49
</div></div>
36
50
51
+
**Note:** presets use `testMatch`, like Jest does in its defaults. If you want to use `testRegex` instead in your configuration, you MUST set `testMatch` to `null` or Jest will bail.
52
+
37
53
### Advanced
38
54
39
-
The `ts-jest` preset can also be used with other options.
40
-
If you're already using another preset, you might want only some specific settings from the `ts-jest` preset.
55
+
Any preset can also be used with other options.
56
+
If you're already using another preset, you might want only some specific settings from the chosen `ts-jest` preset.
41
57
In this case you'll need to use the JavaScript version of Jest config:
0 commit comments