File: installation.md

package info (click to toggle)
node-ts-jest 29.1.1%2B~cs0.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,408 kB
  • sloc: javascript: 2,573; makefile: 19
file content (46 lines) | stat: -rw-r--r-- 1,476 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
id: installation
title: Installation
---

### Dependencies

You can install `ts-jest` and dependencies all at once with one of the following commands.

```bash npm2yarn
npm install --save-dev jest typescript ts-jest @types/jest
```

:::tip

Tip: If you get an error with the following `npm` commands such as `npx: command not found`, you can replace `npx XXX` with `node node_modules/.bin/XXX` from the root of your project.

:::

### Jest config file

#### Creating

By default, Jest can run without any config files, but it will not compile `.ts` files.
To make it transpile TypeScript with `ts-jest`, we will need to create a configuration file that will tell Jest to use a `ts-jest` preset.

`ts-jest` can create the configuration file for you automatically:

```npm tab
npx ts-jest config:init
```

```Yarn tab
yarn ts-jest config:init
```

This will create a basic Jest configuration file which will inform Jest about how to handle `.ts` files correctly.

You can also use the `jest --init` command (prefixed with either `npx` or `yarn` depending on what you're using) to have more options related to Jest.
However, answer `no` to the Jest question about whether or not to enable TypeScript. Instead, add the line: `preset: "ts-jest"` to the `jest.config.js` file afterwards.

#### Customizing

For customizing jest, please follow their [official guide online](https://jestjs.io/docs/en/configuration.html).

`ts-jest` specific options can be found [here](options).