我正在尝试对打字稿的反应运行uni测试。
以下是我正在使用的npm软件包:
"@types/enzyme": "^3.10.4",
"@types/enzyme-adapter-react-16": "^1.0.5",
"@types/jest": "^25.0.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.15.2",
"enzyme-to-json": "^3.4.3",
"jest": "^25.0.0",
"jest-cli": "^25.0.0",
"ts-jest": "^24.3.0"
est.config.ts
module.exports = {
roots: ["<rootDir>/src"],
transform: {
"^.+\\.tsx?$": "ts-jest"
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
testEnvironment: "node",
globals: {
"ts-jest": {
diagnostics: {
warnOnly: true
}
}
},
// Setup Enzyme
snapshotSerializers: ["enzyme-to-json/serializer"],
setupFilesAfterEnv:
[
"<rootDir>/src/setupEnzyme.ts"
]
};
setupEnzyme.ts
import { configure } from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';
configure({ adapter: new EnzymeAdapter() });
测试功能
export const sum = (...a: number[]) => a.reduce((acc, val) => acc + val, 0);
测试
import { sum } from './foo';
/**
* Basic Example
*/
test('basic', () => {
expect(sum()).toBe(0);
});
test('basic again', () => {
expect(sum(1, 2)).toBe(3);
});
/**
* Async Example
*
* Jest has built-in async/await support. e.g.
*/
test('basic async', async () => {
expect(sum()).toBe(0);
});
test('basic async again', async () => {
expect(sum(1, 2)).toBe(3);
});
foo.ts和foo.test.ts位于 tests 文件夹中。
错误是:
FAIL src / 测试 /foo.ts ●测试套件无法运行
Your test suite must contain at least one test.
at onResult (node_modules/@jest/core/build/TestScheduler.js:163:18)
PASS src / 测试 /foo.test.ts
测试套件:1个失败,1个通过,总共2个
测试:4次通过,总共4次
快照:共0个
时间:1.714s,估计2s
运行所有测试套件。
npm ERR!代码ELIFECYCLE
npm ERR! errno 1
npm ERR! wasyster.git.com@0.0.1测试:jest
npm ERR!退出状态1
npm ERR!
npm ERR!在wasyster.git.com@0.0.1测试脚本处失败。
npm ERR! npm可能不是问题。上面可能还有其他日志记录输出。
npm ERR!可以在以下位置找到此运行的完整日志: npm ERR! C:\ Users \ wasyster \ AppData \ Roaming \ npm-cache_logs \ 2020-01-15T16_23_16_125Z-debug.log
在我的文件夹结构中,有一个 .babelrc 文件,内容如下:
{
"presets": ["react", "es2015", "stage-0"],
"plugins": ["emotion", "transform-react-jsx"]
}
如果需要更多信息,我可以提供任何配置文件。
thnx