我只想测试文件位于src外部的特定测试目录中。
简单的例子:
simple-app
1.src
2.testsjest配置:
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
verbose: true,
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
snapshotSerializers: ["enzyme-to-json/serializer"],
setupFilesAfterEnv: ["<rootDir>src/setupEnzyme.ts"],
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less|scss|sass)$": "identity-obj-proxy"}
};tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}我在package.json中通过以下方式指定了我的测试命令:
"test:local": "jest ./tests/local.test.ts",我已经试过很多次了,但都不起作用。有什么能帮上忙的吗?
发布于 2019-12-17 14:11:56
在jest config中,如果您想测试外部src目录,则应该删除src路径。
下面是示例:它应该看起来像roots: ['<rootDir>/'],。我以为是工作。
https://stackoverflow.com/questions/59264105
复制相似问题