在withrouter(component)中使用queryByText开玩笑的测试用例

时间:2019-08-23 09:10:36

标签: reactjs jestjs react-testing-library

我无法为withrouter包装的组件编写测试用例。我将测试用例写为

it('should render all subpageHeader details', () => {
  const { queryByText } = render(
    <Router history={mockHistory}>
      <SubPageHeader {...defaultProps} />
    </Router>
  );
  const backText = queryByText('Go back to reservation details');
  expect(backText).toBe({});  
})

并将组件导出为

export default withRouter(SubPageHeader);

我无法使用queryByText从组件中获取文本。我遇到错误

 received value must be an HTMLElement or an SVGElement.
Received has value: null

任何人请给我一个解决方案

0 个答案:

没有答案