安装依赖:

1
yarn add -D jest ts-jest

配置 ts

在测试文件加下,添加tsconfig.json

1
2
3
4
5
6
7
{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs"
  },
  "extends": "jest"
}

配置 jest

添加 js.config.js

1
2
3
4
5
6

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  testMatch: ['**/test/**/*.test.ts'],
}