小编Mu *_*Kim的帖子

Jest 无法解析 preact 中的 TSX

我正在尝试使用 TypeScript 在 Preact 应用程序中使用 Jest 和酶运行测试。

\n\n

我收到 Jest 遇到意外令牌错误:

\n\n
FAIL  src/app/app.test.tsx\n  \xe2\x97\x8f Test suite failed to run\n\n    Jest encountered an unexpected token\n\n    This usually means that you are trying to import a file which Jest cannot parse, \n     e.g. it\'s not plain JavaScript.\n...\n    Details:\n\n    src/app/app.test.tsx:10\n        const wrapper = enzyme_1.mount(<app_1.default optOutUrl="none"/>);\n                                       ^\n\n    SyntaxError: Unexpected token <\n\n    at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1059:14)\n
Run Code Online (Sandbox Code Playgroud)\n\n

在看到此存储库中的TypeScript 示例后,我更改了 jsx 选项以在tsconifg.json. 但它对我的项目环境没有帮助:

\n\n
Cannot find module \'react\' from \'styled.js\'\n\n    However, Jest …
Run Code Online (Sandbox Code Playgroud)

jestjs enzyme preact

5
推荐指数
0
解决办法
742
查看次数

标签 统计

enzyme ×1

jestjs ×1

preact ×1