javascript - Jest 配置没有正确识别要测试的文件
问题描述
我有当前的文件夹结构(其中 test 在我的目录的根目录中):
test
unit
helper
helper.js
helper2
helper2.js
我的jest.config.js
外观如下(此配置文件位于我文件夹的根目录中):
module.exports = {
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: ['**/*.{js,jsx}', '!**/node_modules/**'],
coverageDirectory: './coverage',
roots: ['<rootDir>/test'],
coverageReporters: ['text'],
rootDir: '.',
reporters: ['default'],
};
当我运行命令时:jest --verbose
我收到No tests found, existing with code 1
. 我的笑话配置中有什么问题需要修改吗?
解决方案
即使您修改了这个roots
笑话,仍然有testMatch。默认情况下,它的值为
"testMatch": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)"
],
因此您可以将其更改为:
"testMatch": [
"**/*.[jt]s?(x)",
],
注意:通过运行jest --showConfig
,您将对所有配置有一个很好的概述,并了解可能需要更改的其他内容
推荐阅读
- javascript - Magento 2未捕获的错误:脚本错误:ko
- ios - 如何为 AVPlayer 编写单元测试用例?
- asp.net - 如何根据数据过滤 ASP.net 核心中的结果
- javascript - 如何在使用固定结构时在 ngFor 中将索引值增加和更新 2
- r - r中的箱形图中的附加轴
- git - 用于识别创建特定分支的源的 Git 命令
- html - 从 HTML 文件打开 Office 文档
- vim - 进入插入模式时,Vim 文件类型插件执行了两次?
- ansible - 在 Ansible 中,如何获取分配给主机的角色列表?
- sql - 从 XML 中获取变量,解析它,然后形成一个 SQL 查询