Answer the question
In order to leave comments, you need to log in
How to correctly change the state in the Jest / Enzyme parent component?
I have a main Todo component which has a state in it . In this state , I store todos and name , which is entered through input. Input I have a separate component, into which I just pass props: Tell me, how can I change the state ( name ) in the parent Todo
from the shallow TodoInput to check that onChange is correctly processed in the inpute?
<TodoInput onChange={this.handleInput} />
Answer the question
In order to leave comments, you need to log in
Resolved the issue. You need to mount the parent and then find the desired input by the selector, which you can then do something like this:
wrapper.find('.todo__form-input').simulate('change', { target: { value: '' } });
Don't use Enzyme when testing React apps, read the documentation.
https://reactjs.org/docs/testing.html#tools
Use the recommended packages - Jest and React Testing Library.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question