具有withRouter的组件的测试用例

时间:2019-07-23 06:43:31

标签: reactjs testing

组件“ B”中具有withRouter。在组件“ B”中为div编写测试用例时,结果是找不到组件。

import React from 'react';
import { withRouter } from 'react-router-dom';

const B = withRouter(({ history }) => {
<div className='myClassName'> xyz </div>
});

export default B;
import React from 'react';
import { shallow } from 'enzyme';
import B from '../someFileA';

describe('B component', () => {
  const component = shallow(<B />);
  it('render B', () => {
      shallow(<B />);
  });

  it('should verify class name', () => {
    expect(component.find('div.myClassName')).toHaveLength(1);
  });
});

我遇到的错误是:

期望(接收到).toHaveLength(预期)

Expected length: 1
Received length: 0

0 个答案:

没有答案