模态酶安装单元测试:未定义MutationObserver

时间:2019-02-20 16:37:42

标签: reactjs jestjs enzyme

我正在尝试对反应模式进行单元测试:

import React from "react";
import { mount } from "enzyme";
import Modal from ".";
import "wicg-inert";
import "animate.css";

describe("Modal component", () => {
  describe("When props is missing", () => {
    it("should raise an exception", () => {
      expect(() => mount(<Modal />)).toBeDefined();
    });
  });
});

此消息失败: 测试套件无法运行

ReferenceError: MutationObserver is not defined

  4 | import classnames from "classnames";
  5 | import Button, { ButtonGroup } from "components/Button";
> 6 | import "wicg-inert";
  7 | import "animate.css";
  8 |
  9 | import "./Modal.scss";

  at new InertManager (node_modules/wicg-inert/dist/inert.js:537:28)
  at node_modules/wicg-inert/dist/inert.js:792:22
  at node_modules/wicg-inert/dist/inert.js:2:66
  at Object.<anonymous> (node_modules/wicg-inert/dist/inert.js:5:2)
  at Object.<anonymous> (src/components/Modal/Modal.jsx:6:1)
  at Object.<anonymous> (src/components/Modal/index.mjs:1:318)
  at Object.<anonymous> (src/components/Modal/Modal.test.js:3:32)

我的印象是,由于酶模拟DOM的限制,该操作失败了。可以用react-test-library解决吗?还是酶本身?

0 个答案:

没有答案