jest测试
# 搭配eslint使用
# 安装
yarn add --dev eslint eslint-plugin-jest
# 使用
//.eslintrc.js
{
"plugins": ["jest"]
}
1
2
3
4
2
3
4
自定义配置一些规则
{
"rules": {
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error"
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 仅仅在测试文件中使用
在eslint配置中overrides (opens new window)字段下添加规则
"overrides": [
{
"files": ["test/**"],
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"],
"rules": { "jest/prefer-expect-assertions": "off" }
}
],
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 设置版本
避免在缓存多个版本的情况下使用了错误的版本
settings: {
jest: {
version: require('jest/package.json').version,
},
},
1
2
3
4
5
2
3
4
5
上次更新: 2022/07/03, 15:02:21