Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Jest testPathIgnorePatterns(React、Jest、Regex)忽略文件名约定_Regex_Reactjs_Jestjs - Fatal编程技术网

如何使用Jest testPathIgnorePatterns(React、Jest、Regex)忽略文件名约定

如何使用Jest testPathIgnorePatterns(React、Jest、Regex)忽略文件名约定,regex,reactjs,jestjs,Regex,Reactjs,Jestjs,我试图建立一个惯例,忽略任何遵循模式的测试。如果您希望jest在npm测试期间忽略它,那么文件名将如下所示 DISABLED.MyComponent.test.js 尝试使用testPathIgnorePatterns testPathIgnorePatterns:['/src/**/DISABLED.{*}.js'], 错误可能是它仍在运行,或者它抛出了一个regex无效的错误 testPathIgnorePatterns是一个regex模式数组,它忽略与列出的表达式匹配的任何路径,并且还应该

我试图建立一个惯例,忽略任何遵循模式的测试。如果您希望jest在npm测试期间忽略它,那么文件名将如下所示

DISABLED.MyComponent.test.js

尝试使用testPathIgnorePatterns


testPathIgnorePatterns:['/src/**/DISABLED.{*}.js'],


错误可能是它仍在运行,或者它抛出了一个regex无效的错误

testPathIgnorePatterns
是一个regex模式数组,它忽略与列出的表达式匹配的任何路径,并且还应该包含默认的
“/node\u modules/”
。因此,如上所述,它不会帮助您忽略特定文件:

因此,您最好将忽略的测试移动到s的单独文件夹中,例如

"jest": {
  "testPathIgnorePatterns": [
    "/node_modules/",
    "<rootDir>/ignore/this/path/" 
  ]
}
“开玩笑”:{
“testPathIgnorePatterns”:[
“/node_modules/”,
“/ignore/this/path/”
]
}
Jest用于匹配测试文件,因此在中使用
作为默认条目的前缀!(已禁用。)
应执行此操作

package.json
{
  // ... rest of the package
  "jest": {
    "testMatch": [
      "**/__tests__/**/!(DISABLED.)*.[jt]s?(x)",
      "**/!(DISABLED.)?(*.)+(spec|test).[tj]s?(x)"
    ]
  }
}

旁注:您还可以通过将主
descripe
块重命名为
xdescripe
descripe.skip
来“禁用”测试文件,这将提供跳过测试的可见性,而不是完全忽略该文件

Test Suites: 1 skipped, 11 passed, 11 of 12 total
Tests:       2 skipped, 112 passed, 114 total

顾名思义,此属性仅用于忽略paths@Teneff有没有关于使用其他属性的建议?谢谢,这很有道理,但不太适合我的用例。不过我会记住的。我真的希望我可以基于某种类型的命名约定禁用,但这将是我的备份计划。禁用语法仍然不适用于那些glob,但我更喜欢你的旁注,可见性很重要。谢谢@Teneff