【发布时间】:2021-08-14 08:00:12
【问题描述】:
我正在使用 jest 和 ts-jest 配置方式,ts-jest 在他们的文档中描述。
如果我运行yarn test --listTests,我可以看到我想要运行的测试文件:processNewUser.ts 包含在我项目的__test__ 文件夹的输出中。
我只能使用 yarn test --testPathPattern='processNewUser' 运行该测试
但如果我尝试使用 yarn test --testNamePattern='Processes new user. Auth' 这是测试的名称,那么每个测试都会运行,包括所有没有指定名称字符串的测试。
与以下内容相同:
yarn test -t="Auth"
yarn test -t Auth
yarn test --testNamePattern "Auth"
jest Auth
jest -t="Processes"
等等等等
以及每个语法组合。还尝试了命名describe 函数包装器而不是测试。没有运气。
我的tsconfig.json 是:
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"outDir": "dist",
"sourceMap": true,
"allowJs": true,
"strict": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"removeComments": false,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"lib": [
"ES2020.Promise",
"ES2015.Iterable",
"ES2015.Symbol.WellKnown"
],
},
"include": ["src/**/*"],
}
我的jest.config.ts 是:
import type {Config} from '@jest/types';
const config: Config.InitialOptions = {
clearMocks: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
preset: 'ts-jest',
setupFiles: ['dotenv/config'],
setupFilesAfterEnv: ['./jest.setup.js'],
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.ts?$': 'ts-jest',
},
transformIgnorePatterns: ['/node_modules/', '\\.pnp\\.[^\\/]+$'],
}
export default config;
Yarn 脚本只是:"test": "jest",
我希望它能够使用 auth 标记测试,例如运行所有身份验证测试。
有什么帮助吗?
【问题讨论】:
标签: typescript unit-testing testing jestjs ts-jest