Error: This method is only meant to be run on single node. 0 found instead
You don't find any node because the element that you try to reach is in another level. Select a specific element by the class, id.. and try this
wrapper.find('LoginForm')
.dive()
.find('.CLASS_NAME_OF_ELEMENT')
.simulate('click');
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.