用Jest和IntelliJ进行单元测试

时间:2020-07-08 09:54:15

标签: jestjs

我在intellij开玩笑的单元测试时出错,我不知道如何解决。

简单测试:

import React from 'react';
import { render, screen } from '@testing-library/react';
import TestComponenent from "./tests/Testcomponent";

test('test TestComponent', () => {
    render(<TestComponenent />);
    expect(screen.getByText("test")).toBeInTheDocument();
});

在IntelliJ中运行此测试时,出现以下错误:

●测试套件无法运行

TypeError: Class constructor Spec cannot be invoked without 'new'

  102 | function createdPatchedSpec(OriginalSpec, registry) {
  103 |   function PatchedSpec(attrs) {
> 104 |     OriginalSpec.apply(this, arguments);
      |                  ^
  105 |     if (attrs && attrs.id) {
  106 |       registry[attrs.id] = this;
  107 |     }

  at new PatchedSpec (../../../../Program Files/JetBrains/IntelliJ IDEA 2018.3.4/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-jasmine.js:104:18)
  at Object.<anonymous> (src/TestComponent.test.js:5:1)

版本: 笑话包:3.4.1 Nodejs:12.16.3

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

已解决:我安装了IntelliJ的最新版本。