我正在为我的一个组件写测试用例,这个组件有路由器(使用withrouter).and,我得到错误wrapper.find不是一个函数。基本需求是需要在我的渲染中检查标签的存在,还需要检查标签的aria-label属性
const Component = () => const WrappedComponent =withRouter(组件)
describe('Error Boundary...', () => {
it('should render children when no error is encountered', () => {
const wrapper = ReactTestRenderer.create(
<Router><WrappedComponent /></Router>
);
expect(wrapper.toJSON().type).toEqual('div');
expect(wrapper.toJSON()find('a').attr('aria-label')).toEqual('Hello World');
});
});发布于 2019-08-01 17:28:24
您不应该在expect行中调用.toJSON()。
describe('Error Boundary...', () => {
it('should render children when no error is encountered', () => {
const wrapper = ReactTestRenderer.create(
<Router><WrappedComponent /></Router>
);
expect(wrapper.root.type).toEqual('div');
expect(wrapper.root.find('a').attr('aria-label')).toEqual('Hello World');
});
});https://stackoverflow.com/questions/57305080
复制相似问题