Type缺少类型'ElementClass'中的以下属性:context,setState,forceUpdate,props,refs

问题描述 投票:0回答:1

我正在将NextJS与Typescript一起使用。我正在尝试使用Jest + Enzyme测试我的应用程序。我收到以下错误消息:

**测试套件无法运行

TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
__tests__/Quest.spec.tsx:15:27 - error TS2605:

JSX元素类型'Quest'不是JSX的构造函数元素。类型“ Quest”缺少类型“ ElementClass”中的以下属性:context,setState,forceUpdate,props,refs

**

我已经添加了我的测试文件的代码和我为其编写测试的代码:

Quest.spec.tsx(测试文件)

import * as React from 'react';
import {mount} from 'enzyme';
import Quest from '../Quest';

describe('Quest page', () => {
  it('should render without throwing an error', function () {
    const wrapper = mount(<Quest/>);
  })
}) 
typescript types jestjs enzyme next.js
1个回答
0
投票

我通过以下方式解决了这个问题:yarn upgrade @ types / react @ latest,我同时更新了test.tsx文件和我的主代码文件的import语句,以便从'react'导入*作为React;

© www.soinside.com 2019 - 2024. All rights reserved.