cocos支持jest

安装 jest

1
npm install --save jest ts-jest @types/jest

修改配置 package.json

1
2
3
4
5
6
7
"scripts": {
"test": "jest"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
}
  • jest 是jest配置
  • scripts 是指定 npm test 工具

jest 插件

vscode 安装 jest插件

这样当编辑脚本时 就可以自动运行测试了

image-20220108114306513

修改vscode配置 就可以仅修改 test 文件时 才重新运行当前 test 文件

1
2
3
4
5
6
7
"jest.autoRun": {
"watch": false,
"onStartup": [
"all-tests"
],
"onSave": "test-file"
}