我正在尝试为我的 React 组件编写一个测试,使用 TypeScript、Jest 作为我的测试运行程序和 Enzyme 来测试我的 React 组件。每当我将我的组件传递给shallowEnzyme 函数时,我都会收到 ts 错误“'Navbar' 指的是一个值,但在此处被用作类型。”,并且在下面我收到 eslint 错误“解析错误:'>' 预期” .
我在其他一些组件上尝试过,当shallow作为参数传递给函数时,所有组件都出现相同的错误。我怀疑这可能与我的 TS 配置有关,但对于我的生活,我似乎无法找到解决方案。
这是 Navbar.tsx 的代码:
import React from 'react';
import { shallow } from 'enzyme';
import Navbar from './Navbar';
describe('Navbar component', () => {
let component;
beforeEach(() => {
component = shallow(<Navbar />); // Error being desplayed here
});
it('should render without errors', () => {
expect(component).toMatchInlineSnapshot();
expect(component.length).toBe(1);
expect(component).toBeTruthy();
});
});
Run Code Online (Sandbox Code Playgroud)
还发布我的配置文件:
配置:
{
"compilerOptions": {
"target": "es5", …Run Code Online (Sandbox Code Playgroud)