> For the complete documentation index, see [llms.txt](https://kdongs.gitbook.io/kdocs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kdongs.gitbook.io/kdocs/jest/about.md).

# About

## Install

For TypeScript install Jest with [`ts-jest`](https://kulshekhar.github.io/ts-jest/docs/getting-started/installation) preprocessor with:

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

Because we are running with `ts-jest` create the `jest.config.js` file, which will inform Jest how to handle `.ts` files correctly.

```bash
npx ts-jest config:init
```

## [Running](https://jestjs.io/docs/cli)

Test files for Jest are named `<file>.test.ts`.

### By specific filename

#### Specific filename AND path

Run only the tests that were specified with their exact paths.

```bash
npx jest --runTestsByPath [path]/[filename]
```

#### Specific filename

Find and run the tests that cover a space separated list of source files.

It will regex only by the specified name, so if multiple files have the same name it will execute all of them.

```bash
npx jest --findRelatedTests [filename]
```

### With coverage

```bash
npx jest --coverage
```

### On watch mode

Watch files for changes and rerun tests.

#### To rerun only changed files

```bash
# Runs `jest -o` by default
npx jest --watch
```

#### To rerun all files

```bash
npx jest --watchAll
```
