javascript - 使用 Jest 忽略 testMatch 中的特定文件夹模式

标签 javascript unit-testing pattern-matching jestjs

我试图忽略 Jest 的 testMatch 模式中的特定文件夹。

我在 __tests__ 文件夹中进行了测试,我希望能够将文件夹 __config__ 放入其中,其中应忽略所有文件。

/__tests__
  /__config__
    someConfig.jsx
  /MyComponent.jsx
/MyComponent.jsx

我在 __tests__ 文件夹中的测试将从 __config__ 文件夹导入文件,所以我不想用 transformIgnorePatterns 忽略它们.

但如果我不忽略该文件夹,Jest 会尝试在该文件夹中运行并返回错误:

FAIL src/components/__tests__/__config__/someConfig.jsx

Your test suite must contain at least one test.

我尝试了几种不同的模式,但找不到忽略 __config__ 文件夹的方法

testMatch: [
  "**/__tests__/!(__config__)/**/*.(js)?(x)", // Doesn't work
  "**/__tests__/(**|!__config__)/*.(js)?(x)", // Doesn't work
  "**/__tests__/(**|?!__config__)/*.(js)?(x)", // Doesn't work
  "**/__tests__/{**,!__config__}/*.(js)?(x)", // Doesn't work
],

知道如何忽略这样的子文件夹吗?

最佳答案

请尝试使用 testPathIgnorePatterns

如果测试路径匹配任何模式,它将被跳过。

使用字符串标记来包含项目根目录的路径。

关于javascript - 使用 Jest 忽略 testMatch 中的特定文件夹模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47819927/

相关文章:

javascript - fullscreenchange 事件未在 Chrome 中触发

javascript - 如何在javascript数组中存储元素?

javascript - 无论我如何尝试,Gatsby.js 的 <Link> 问题

c# - 使用实际类而不是类副本的单元测试

python - 再次计算重叠的正则表达式匹配

python - Python 中的正则表达式 [^.]

javascript - 在 JavaScript 中设置和获取 bool 对象属性

c# - 使用 .runsettings 文件时,代码覆盖率中不包含异步方法

java - 结束 JUnit 测试

scala - Scala 与 Haskell 中 List[T] 和 Set[T] 上的模式匹配 : effects of type erasure