我是新来的,我正在做一个项目。我遇到了.ts和.tsx扩展。我不明白我应该在哪里使用.tsand .tsx。非常感谢您对此的任何帮助。谢谢!
我正在尝试为我的 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) 我在 react redux 中使用 typescript 有一个 react 应用程序。我正在使用 jest 编写测试。根据惯例,我对测试文件的扩展名应该是什么感到困惑。无论是 js/ts 还是 tsx。
任何线索将不胜感激。