在 package.json 中使用 Jest --testNamePattern=<regex> 或 -t 选项

obe*_*roi 3 testing node.js jestjs

如何在 package.json 中使用 Jest--testNamePattern=<regex>-toption

jest -t /.*flow.spec.js$/ 
Run Code Online (Sandbox Code Playgroud)

或者

jest -t='.*flow.spec.js$'
Run Code Online (Sandbox Code Playgroud)

不起作用。

Jos*_*rel 5

这种情况下的混淆--testNamePattern是用于匹配测试套件中的测试名称而不是文件。提供的示例可能与预期不符,匹配:

describe('Test suite', () => {
  test('something.flow.spec.js', () => {
    //... tests here
  });
});
Run Code Online (Sandbox Code Playgroud)

要改为按文件名匹配,--testPathPattern应使用该参数。在这种情况下尝试:

--testPathPattern=.*flow.spec.js$
Run Code Online (Sandbox Code Playgroud)