Ant*_*ine 5 javascript regex jestjs
答案:它与正则表达式无关,但与文件的位置有关jest.config.js,更改rootDir配置可以解决问题
我在 regex101.com 中有一个有效的正则表达式,但我可以让它在 Jest 中工作
__tests__\/.*test.[jt]sx?$
Run Code Online (Sandbox Code Playgroud)
给出的结果(regex101):
__tests__/__config/jest.config.js -> no
__tests__/app.test.js -> yes
__tests__/app.test.ts -> yes
__tests__/app.test.tsx -> yes
__tests__/api/app.test.js -> yes
__tests__/api/app.test.not -> no
__tests__/api/api2/api3/app.test.js -> yes
toto.test.js -> no
Run Code Online (Sandbox Code Playgroud)
这正是我想要的,但是当我更新时jest.config.js
笑话配置:
module.exports = {
testRegex: ["__tests__/.*test.[jt]sx?$"],
};
Run Code Online (Sandbox Code Playgroud)
它没有找到任何东西。
我想要做什么:我想将与单元测试相关的所有内容存储在__tests__文件夹内,包括jest.config.jsJest 和其他不必运行的内容。
在package.json__tests__中运行文件夹内的配置
...
"test": "jest --config ./__tests__/__config/jest.config.js"
...
Run Code Online (Sandbox Code Playgroud)
所以它给了我类似的东西:
__tests__/
__config/
jest.config.js -> do not run
dabatase.js -> do not run
user/
user.test.js -> run this
user.mock.js -> do not run
Run Code Online (Sandbox Code Playgroud)
所以基本上只有以该结尾的内容才.test.js/ts在__tests__文件夹内
这是一个具有当前(非功能性)配置的小存储库:Github Repo
谢谢
| 归档时间: |
|
| 查看次数: |
1482 次 |
| 最近记录: |