Reputation: 1530
Per the enzyme docs here the following stanza should find a selector by ID:
it('Should render the Select Vehicle entry', () => {
let component = shallow(<VehicleMenu {...initialState} />);
expect(component.find("#vehMenuSelect")).to.have.lengthOf(1);
});
But the .to.have.[...]
method never works for me anywhere in my code, and always returns:
TypeError: Cannot read property 'have' of undefined
no matter which selector type I use (in this case find).
This works, and is what I have been using:
it('Should render the Select Vehicle entry', () => {
let component = shallow(<VehicleMenu {...initialState} />);
expect(component.find("#vehMenuSelect").length).toBe(1);
});
.toBe()
always works. Why do I get that error when using the methods described in the current enzyme docs? THis is with enzyme 3.9.0
and enzyme-adapter-react-16 1.12.1
.
Upvotes: 0
Views: 153
Reputation: 1752
The example from the docs of enzyme is not using jest. You should follow the docs of jest. Change it to toHaveLength
instead of to.have.length
Upvotes: 1