Answer the question
In order to leave comments, you need to log in
Why can't I simulate an event in Enzyme?
I made a form in React using Formik and Material-UI. There is one field "Card number" in the form. If you enter the number correctly and press the button, you will receive the message “Card added”: this is done through the state.
I am writing a unit test using Jest and Enzyme. Does not pass the test, which simulates data entry and button press. The error is the following:
Method “simulate” is meant to be run on 1 node. 0 found instead
but the field and the button are there, and it's even been tested. What is the problem? Please help me fix it. Answer the question
In order to leave comments, you need to log in
Judging by the text of the error, Enzyme did not find the component on which you want to simulate the callback. There can be two reasons: either you misspelled the selector, or the name of the component when rendering does not look like what you think. To find the error, try typing wrapper.debug() to the console and see what the render looks like, maybe you will find something interesting. Well, in any case, try to give the component an id and search by it, it usually works.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question