Enzyme: simple .to.have not working

痴心易碎 提交于 2021-02-16 13:59:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!