nx/packages/jest/docs/jest-examples.md
2022-09-23 20:09:41 +00:00

55 lines
1.1 KiB
Markdown

Jest can be configured in many ways, but primarily you'll need to at least have the jestConfig options
```json
"test": {
"executor": "@nrwl/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": "@nrwl/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": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/my-lib/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true
}
}
}
```
```bash
nx affected --target=test --configuration=ci
```
Learn more [about _affected_](/concepts/affected)