Skip to content

Unit testing

Mark Doeswijk edited this page Oct 23, 2018 · 1 revision

We mostly use Jest for our JavaScript/TypeScript project unit tests. Below are the instruction to add unit test support to an exisiting project.

Create a test folder in the root of your project and install jest:

npm i -D jest ts-jest @types/jest

You can (and should) write your tests in TypeScript and files are called xxx.spec.ts

Add this to your package.json file:

  "jest": {
    "transform": {
      ".(ts|tsx)": "ts-jest"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ],
    "coveragePathIgnorePatterns": [
      "/node_modules/",
      "/test/"
    ],
    "coverageThreshold": {
      "global": {
        "branches": 90,
        "functions": 95,
        "lines": 95,
        "statements": 95
      }
    },
    "collectCoverage": true
  },
  "scripts": {
    ...
    "test": "NODE_ENV=test && jest --silent",
  },
Clone this wiki locally