我已经使用玩笑和酶为反应应用开发了单元测试。我正在使用Jest版本25.7.1。当我运行测试时,它失败并显示以下错误。我不确定为什么它不喜欢import关键字。
FAIL src / components / App.test.tsx ●测试套件无法运行
LiveData
这是我在package.json中最有趣的配置,
D:\Dev\ps-visualizer\ClientApp\node_modules\@svgdotjs\svg.js\src\main.js:2
import './modules/optional/arrange.js'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
at Object.<anonymous> (node_modules/@bentley/imodeljs-markup/lib/Markup.js:10:18)
tsconfig是这样定义的,
{
"browser": true,
"verbose": true,
"collectCoverageFrom": [
"src/**/*.{js,jsx,ts,tsx}",
"!src/**/*.d.ts"
],
"setupFilesAfterEnv": [
"<rootDir>/src/setupTests.ts"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.test.json"
}
},
"roots": [
"<rootDir>/src"
],
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
"<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
],
"transform": {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tsx?$": "ts-jest"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
"^.+\\.module\\.(css|sass|scss)$"
],
"moduleNameMapper": {
"^react-native$": "react-native-web",
"\\.(css|less|scss|json)$": "<rootDir>/__mocks__/styleMock.js",
"^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
},
"moduleFileExtensions": [
"web.js",
"js",
"web.ts",
"ts",
"web.tsx",
"tsx",
"json",
"web.jsx",
"jsx",
"node"
]
}