正如说的那样,当您在除1以外的任意数量的节点上运行该错误时,就会发生该错误。
与jQuery类似,您的
find调用将返回一定数量的节点(实际上,这是一个包装器,它知道
find选择器找到了多少个节点)。而且您不能调用
simulate0个节点!或多个。
然后的解决方案是弄清楚选择器(
styles.containerin
wrapper.find(styles.container))为什么返回0个节点,并确保它恰好返回1,然后
simulate将按预期工作。
const container = wrapper.find(styles.container)expect(container.length).to.equal(1)container.simulate('keyup', {keyCode: 27});expect(store.getActions()[0]).to.deep.equal(expectedAction);酶的调试方法在这里非常有用。您可以这样做
console.log(container.debug()),或者也
console.log(container.html())可以确保您的组件在测试过程中按预期方式呈现。



