nx/packages/jest/docs/jest-examples.md
Isaac Mann 61436a64ef
docs(core): inferred targets (#21167)
Co-authored-by: Katerina Skroumpelou <mandarini@users.noreply.github.com>
Co-authored-by: Colum Ferry <cferry09@gmail.com>
Co-authored-by: Emily Xiong <xiongemi@gmail.com>
Co-authored-by: Nicholas Cunningham <ndcunningham@gmail.com>
Co-authored-by: Jason Jean <jasonjean1993@gmail.com>
Co-authored-by: Victor Savkin <mail@vsavkin.com>
Co-authored-by: Jack Hsu <jack.hsu@gmail.com>
2024-02-03 00:14:05 -05:00

55 lines
1.0 KiB
Markdown

Jest can be configured in many ways, but primarily you'll need to at least have the jestConfig options
```json
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "libs/my-lib/jest.config.ts"
}
}
```
It is also helpful to have `passWithNoTests: true` set so your project doesn't fail testing while tests are still being added.
```json
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "libs/my-lib/jest.config.ts",
"passWithNoTests": true
}
}
```
### Snapshots
Update snapshots running with `--update-snapshot` or `-u` for short.
```bash
nx test my-project -u
```
Other times you might not want to allow updating snapshots such as in CI.
Adding a _ci_ configuration is helpful for adding this behavior.
```json
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "libs/my-lib/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true
}
}
}
```
```bash
nx affected --target=test
```
Learn more [about _affected_](/ci/features/affected)