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

1.0 KiB

Jest can be configured in many ways, but primarily you'll need to at least have the jestConfig options

"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.

"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.

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.

"test": {
  "executor": "@nx/jest:jest",
  "options": {
    "jestConfig": "libs/my-lib/jest.config.ts",
    "passWithNoTests": true
  },
  "configurations": {
    "ci": {
      "ci": true
    }
  }
}
nx affected --target=test

Learn more about affected