我有一个自定义的 eslint-config,它有几个用于各种包的插件,包括 jest。我将主要设置为一个索引,它只是扩展其他文件。
长话短说我有一个笑话配置文件。那看起来像。
module.exports = {
plugins: ['jest'],
rules: {
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/valid-expect': 'error',
'jest/no-alias-methods': 'off',
'jest/no-jest-import': 'error',
'jest/no-large-snapshots': ['warn', {maxSize: 300}],
'jest/no-test-prefixes': 'error',
'jest/prefer-to-contain': 'warn',
'jest/prefer-to-have-length': 'warn',
'jest/valid-describe': 'error',
'jest/valid-expect-in-promise': 'error',
'jest/consistent-test-it': 'off',
'jest/lowercase-name': 'off',
'jest/no-hooks': 'off',
'jest/no-jasmine-globals': 'off',
'jest/no-test-callback': 'off',
'jest/prefer-expect-assertions': 'off',
'jest/prefer-to-be-null': 'off',
'jest/prefer-to-be-undefined': 'off',
'jest/require-tothrow-message': 'off',
'jest/expect-expect': 'off',
'jest/no-test-return-statement': 'off',
'jest/prefer-inline-snapshots': 'off',
'jest/prefer-strict-equal': 'off',
'jest/prefer-spy-on': 'off',
'jest/prefer-todo': 'warn',
'jest/prefer-called-with': 'error',
'jest/no-truthy-falsy': 'off',
'jest/no-empty-title': 'error',
'jest/no-mocks-import': 'error',
'jest/no-commented-out-tests': 'warn',
},
env: {
'jest/globals': true,
},
}
Run Code Online (Sandbox Code Playgroud)
运行 lint 任务时,我不断收到错误消息Environment key "jest/globals" is unknown。据我所知,我已经跟踪了配置验证器,但没有任何内容跳出。eslint-plugin-jest 板上没有关于此的开放/关闭问题,我找不到其他人有同样的错误。
另外一个额外的好处是,我还安装了 cypress 插件,它本身有一个环境选项 cypress/globals: true ,它也会引发相同的错误。
有没有人遇到过这种情况并知道为什么(在过去一个月左右)这种情况开始发生。注意:我已经有一段时间了这个配置,这才刚刚开始发生。
编辑:我刚刚降级到 eslint^6.1.0,这个问题不再存在。6.1.0 和 6.4.0 之间的某些东西导致了这个问题。
小智 20
把它放进去extends为我解决了这个问题。
...
"extends": ["eslint:recommended", "plugin:jest/recommended"],
...
Run Code Online (Sandbox Code Playgroud)
小智 10
我也遇到过这个问题,通过以下步骤解决:
react-app/jest:"eslintConfig": {
"extends": [
"react-app",
"react-app/jest" // REMOVE THIS
]
}
Run Code Online (Sandbox Code Playgroud)
请遵循本指南:
https://www.npmjs.com/package/eslint-plugin-jest
基础是: npm i --save-dev eslint-plugin-jest
将此添加到您的.eslintrc文件中:
"plugins": ["jest"]
Run Code Online (Sandbox Code Playgroud)
那么你的 env 属性"jest/globals": true应该可以工作。
对我来说,这只是更改.eslintrc.json配置的问题
"env": {
...
"jest/globals": true
...
}
Run Code Online (Sandbox Code Playgroud)
到:
"env": {
...
"jest": true
...
}
Run Code Online (Sandbox Code Playgroud)
请参阅此处:https://eslint.org/docs/latest/user-guide/configuring/language-options#specifying-environments
| 归档时间: |
|
| 查看次数: |
7468 次 |
| 最近记录: |