组件“ 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