问题
From the docs something like this should be possible:
const wrapper = mount(<Foo name="foo" />);
expect(wrapper.find('.foo')).to.have.length(1);
But in my case this throws an error saying cannot read property have of undefined.
Using this works though:
expect(wrapper.find('.foo').length).toBe(1);
回答1:
Your expect
function is probably expect-enzyme, which has camelCase methods (toBe()
), .to.have
is dot separated expect
notation, as seen in these docs :
http://chaijs.com/api/bdd/
vs the expect-enzyme
https://github.com/PsychoLlama/expect-enzyme
So your "version" of expect has a different API, that's all.
来源:https://stackoverflow.com/questions/43813802/enzyme-simple-to-have-not-working