reactjs - 意外的令牌<在反应打字稿中很浅
问题描述
我正在使用 react + typescript + jest 完成了初始设置,但是当我尝试运行测试时,我收到以下错误:
const component = enzyme_1.shallow(<Dummy_1.default />).contains(<h1>Hello</h1>);
^
SyntaxError: Unexpected token <
包.json
"jest": {
"setupFiles": [
"<rootDir>/tests/setup/test-shim.js",
"<rootDir>/tests/setup/test-setup.js"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"testMatch": [
"**/tests/*.(ts|tsx|js)"
]
},
测试文件:
import React from 'react';
import { shallow } from 'enzyme';
import Dummy from '../src/Dummy';
it('renders dummy page', () => {
const component = shallow(<Dummy />).contains(<h1>Hello</h1>);
expect(component).toBeTruthy();
});
我试过开玩笑地添加预设,但我只得到了同样的错误。我还没有安装 babelrc 我需要安装它吗?我已经使用 create-react-app 创建了应用程序
解决方案
推荐阅读
- javascript - 难倒练习 Javascript 制作 D20 骰子滚轮
- javascript - Firefox CSS过渡在mouseleave上跳过动画
- flutter - 颤振 - 图标主题数据。深色模式的图标颜色会更改,但 Drawer() 中的浅色模式不会更改
- git - 执行 git 命令时出错
- swift - 如何快速将带有 PID 号的窗口放在前面?
- python-3.x - python中的端口扫描器无法正常工作
- powershell - PowerShell - 将属性 BULK 更改为用户列表
- linux - 如何在 GNU 并行中插入睡眠?
- angular - 提交,keyup.enter 不适用于 Angular 10
- flutter - 颤振 - 如何将文本表单字段提交到注册按钮?