【发布时间】:2021-09-16 13:14:42
【问题描述】:
我在两个不同的文件中有两个独立的组件
组件A和组件B
我在 ComponentB
中有一个按钮现在我想测试一下,当点击ComponentB中的特定按钮时,ComponentA应该呈现如下:
import { render, screen, fireEvent } from '@testing-library/react';
import ComponentA from './ComponentA';
import ComponentB from './ComponentB'
test('Component A Comes up on Click of Component B button', () => {
render(<ComponentB />);
const componentBButton = screen.getByRole('button');
fireEvent.click(componentBButton);
expect(<ComponentA />).toBeInTheDocument(); //This throwing an error that receiver must be HTMLElement or SVGElement
});
不幸的是,我在expect(<ComponentA />).toBeInTheDocument(); 行收到此错误Receiver must be HTMLElement or SVGElement
拜托,我是测试新手,我该如何解决这个问题? 谢谢你的意见
【问题讨论】:
标签: reactjs react-testing-library ui-testing