Skip to content

Commit ddc2f79

Browse files
committed
docs(preset): usage of all presets + note about testMatch
1 parent 6985e07 commit ddc2f79

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

docs/user/config/index.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,28 @@ The later is preferred since it's more customizable, but it depends on your need
66

77
## Jest preset
88

9+
### The 3 presets
10+
11+
`ts-jest` comes with 3 presets, allowing to cover 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` (and so TypeScript).<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+
919
### Basic usage
1020

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):
1222

1323
<div class="row"><div class="col-md-6" markdown="block">
1424

1525
```js
1626
// jest.config.js
1727
module.exports = {
1828
// [...]
29+
// Replace `ts-jest` with the preset you want to use
30+
// from the above list
1931
preset: 'ts-jest'
2032
};
2133
```
@@ -27,27 +39,35 @@ module.exports = {
2739
{
2840
// [...]
2941
"jest": {
42+
// Replace `ts-jest` with the preset you want to use
43+
// from the above list
3044
"preset": "ts-jest"
3145
}
3246
}
3347
```
3448

3549
</div></div>
3650

51+
**Note:** presets are using `testMatch`, as Jest's 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+
3753
### Advanced
3854

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 `ts-jest` chosen preset.
4157
In this case you'll need to use the JavaScript version of Jest config:
4258

4359
```js
4460
// jest.config.js
45-
const { jestPreset: tsJestPreset } = require('ts-jest');
61+
const tsJestPresets = require('ts-jest/presets');
62+
63+
const preset = tsJestPresets.defaults
64+
// const preset = tsJestPresets.jsWithTs
65+
// const preset = tsJestPresets.jsWithBabel
4666

4767
module.exports = {
4868
// [...]
4969
transform: {
50-
...tsJestPreset.transform,
70+
...preset.transform,
5171
// [...]
5272
}
5373
}

0 commit comments

Comments
 (0)