我正在将现有的测试转换为使用ts-jest和typescript,我已经找到了所有文件,但是所有测试都失败并显示以下错误:
FAIL src/components/Buttons/__tests__/index.tsx
● Test suite failed to run
Error: No message was provided
我完全不知道发生了什么事情,通过谷歌搜索也找不到任何遇到相同问题的人,这让我感到害怕...
带有jest配置的package.json
"jest": {
"globals": {
"ts-jest": {
"tsConfigFile": "<rootDir>/tsconfig.json",
"babelConfig": {
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
}
},
"setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.ts",
"verbose": true,
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"typeface-roboto|\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
},
"moduleFileExtensions": [
"ts", "tsx", "js", "jsx", "json", "node"
]
},
示例测试文件...
import React from 'react';
import { shallow } from 'enzyme';
import Account from '../account';
it('renders without crashing', () => {
expect(shallow(<Account />)).toBe(1);
});