我一直在尝试设置jest与typescript一起使用,我已经尝试了一堆修复,但没有运气。我得到错误SyntaxError: Unexpected token, expected ";"
,我认为配置不支持typescript代码:https://i.stack.imgur.com/iGBCa.png
如果任何人有任何建议,我会非常感激!
这是我的包。json:
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"collectCoverageFrom": [
"**/*.js",
"**/*.ts",
"!__tests__/util.ts",
"!coverage/**",
"!**/node_modules/**"
],
"transform": {
"^.+\\.tsx?$": "babel-jest"
},
"verbose": true,
"automock": false,
"clearMocks": true,
"setupFilesAfterEnv": [
"jest-extended"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": false,
"isolatedModules": true,
"jsx": "preserve",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": false,
"target": "esnext",
"types": ["@emotion/core", "@types/jest", "jest"],
"rootDir": ".",
"baseUrl": ".",
"noImplicitAny": false,
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
2条答案
按热度按时间rbpvctlc1#
我认为问题出在
transform
的配置上,当我说应该是ts-jest
的时候,你却要求jest对tsx
文件使用babel-jest
。您甚至可以删除
transform
配置,因为默认情况下ts-jest
预设处理ts
和tsx
。unftdfkk2#
使用
esbuild-jest