小编nik*_*krb的帖子

删除了玩笑/酶测试事件监听器

学习玩笑和酶来测试 React 应用程序,使用 create-react-app 引导。

惩戒添加/ removeEventListener崩溃使用unmountshallow,用在警告unmountmount,见下文。有谁知道我做错了什么?

我的测试:

it('should add and remove resize event handler', () => {
  const adder = jest
    .spyOn(global, 'addEventListener')
    .mockImplementation(() => {});
  const remover = jest
    .spyOn(global, 'removeEventListener')
    .mockImplementation(() => {});
  const wrapper = shallow(<App />);
  // this seems to work
  expect(adder).toHaveBeenCalled();
  // causing issues
  wrapper.unmount();
  expect(remover).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)

使用unmountmount

  console.error node_modules/fbjs/lib/warning.js:33
    Warning: Can only update a mounted or mounting component. This usually means …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs enzyme create-react-app

5
推荐指数
1
解决办法
6179
查看次数

标签 统计

create-react-app ×1

enzyme ×1

jestjs ×1

reactjs ×1