Error: This method is only meant to be run on single node. 0 found instead

That error happens when, as it says, you run it with any number of nodes other than 1.

Similar to jQuery, your find call will return some number of nodes (really it’s a single wrapper that knows how many nodes your find selector has found). And you can’t call simulate against 0 nodes! Or multiple.

The solution then is to figure out why your selector (the styles.container in wrapper.find(styles.container)) is returning 0 nodes, and make sure it returns exactly 1, and then simulate will work as you expect.

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);

Enzyme’s debug method is really useful here. You could do console.log(container.debug()), or also console.log(container.html()) to make sure your component is rendering as expected during the test.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)