简体   繁体   English

如何在package.json脚本字段中使用Jest的testNamePattern?

[英]how to use testNamePattern of jest within package.json scripts field?

Honestly, jest of facebook has a bad document. 老实说,facebook jest的文件不好。

I want to use jest -t xxx to update my snapshots. 我想使用jest -t xxx更新快照。

Here is my test, but no one works correctly. 这是我的测试,但没人能正常工作。

  1. jest -u -t='test.tsx'

  2. jest -u -t 'test.tsx'

  3. jest -u -t /test.tsx/

  4. jest -u -t=/test.tsx/

I want to match and update snapshots test files which filename pattern like *.test.tsx . 我想匹配并更新快照测试文件,其文件名模式如*.test.tsx

How can I do that with jest testNamePattern ? 我该如何用jest testNamePattern做到这testNamePattern

First check jest --showConfig to see that you even have the option of --testNamePattern. 首先检查jest --showConfig,以查看您甚至可以选择--testNamePattern。 I faced the same issue, and did not find this option in jest config. 我遇到了同样的问题,并且在jest config中找不到此选项。

So I changed my directory structure and used --testPathPattern option with regex. 因此,我更改了目录结构,并在正则表达式中使用了--testPathPattern选项。 This works. 这可行。

jest --testPathPattern='(tests)/spec/. 开玩笑--testPathPattern ='(测试)/ spec /。 /snapshot-tests/. /快照测试/。 '

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM