【问题标题】:Type is missing the following properties from type 'ElementClass': context, setState, forceUpdate, props, refs类型缺少“ElementClass”类型的以下属性:context、setState、forceUpdate、props、refs
【发布时间】:2020-06-22 09:06:55
【问题描述】:

我正在使用带有 Typescript 的 NextJS。我正在尝试使用 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】:

    我通过以下方式解决了这个问题:yarn upgrade @types/react@latest 并更新了 test.tsx 文件和我的主代码文件的导入语句,以将 * as React from 'react' 导入;

    【讨论】:

      猜你喜欢
      • 2020-01-30
      • 2021-04-20
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-11
      • 2020-10-28
      • 1970-01-01
      相关资源
      最近更新 更多