Jestjs Jest未能在序言中解析TSX
我试图在一个带有TypeScript的Preact应用程序中使用Jest和Ezyme运行测试 我收到一个笑话,遇到意外的令牌错误:Jestjs Jest未能在序言中解析TSX,jestjs,enzyme,preact,Jestjs,Enzyme,Preact,我试图在一个带有TypeScript的Preact应用程序中使用Jest和Ezyme运行测试 我收到一个笑话,遇到意外的令牌错误: FAIL src/app/app.test.tsx ● Test suite failed to run Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse,
FAIL src/app/app.test.tsx
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse,
e.g. it's not plain JavaScript.
...
Details:
src/app/app.test.tsx:10
const wrapper = enzyme_1.mount(<app_1.default optOutUrl="none"/>);
^
SyntaxError: Unexpected token <
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1059:14)
在上面的错误中,它表示与样式化组件相关的文件中的react解析失败。(我正在使用linaria/react
with中的样式化组件。)此问题不会出现在开发和生产环境中
我还试着在下面的配置中使用babel jest
“transform”: {
“^.+\\.t(s|x)$”: “babel-jest”
}
“transform”: {
“^.+\\.t(s|x)$”: “babel-jest”
}
FAIL src/app/app.test.tsx
● Test suite failed to run
src/app/app.tsx: Cannot find module 'react'