我试图建立一个约定来忽略任何遵循模式的测试。如果您希望在 npm 测试期间开 Jest 忽略它,文件名将如下所示。
禁用.MyComponent.test.js
尝试使用 testPathIgnorePatternstestPathIgnorePatterns: ['<rootDir>/src/**/DISABLED.{*}.js'],
错误是它仍在运行,或者它抛出正则表达式无效的错误。
最佳答案
Jest 使用 glob patterns匹配测试文件,因此在 the testMatch
configuration 中添加默认条目的前缀与 !(DISABLED.)
应该做的工作。
package.json
{
// ... rest of the package
"jest": {
"testMatch": [
"**/__tests__/**/!(DISABLED.)*.[jt]s?(x)",
"**/!(DISABLED.)?(*.)+(spec|test).[tj]s?(x)"
]
}
}
旁注:您还可以通过重命名主
describe
来“禁用”测试文件。阻止到 xdescribe
或 describe.skip
,这将提供跳过测试而不是完全忽略文件的可见性Test Suites: 1 skipped, 11 passed, 11 of 12 total
Tests: 2 skipped, 112 passed, 114 total
关于regex - 如何使用 Jest testPathIgnorePatterns (React, Jest, Regex) 忽略文件名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59273284/