0
votes

I'm testing nested Redux containers with Jest and Enzyme.

If a child nested component class is called MyComponent and I shallow render them with Enzyme, they show in a snapshot as:

<Connect(MyComponent) myProp='someValue' /> 

Is there a way to find these containers with Enzyme? The following fail:

expect(wrapper.find(MyComponent)).toHaveLength(1);
expect(wrapper.find('MyComponent')).toHaveLength(1);
expect(wrapper.find('Connect(MyComponent)')).toHaveLength(1);

I know I can use mount instead and test for e.g. class names, but I thought it would make sense to keep the rendering shallow for simplicity and speed.

1

1 Answers

2
votes

Try using Enzyme's .dive() function:

expect(wrapper.dive().find("MyComponent").exists()).toBe(true)