T
T
the5x2020-03-23 10:49:35
Software testing
the5x, 2020-03-23 10:49:35

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

2 answer(s)
T
the5x, 2020-03-23
@the5x

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: '' } });

C
camelCaseVlad, 2020-03-23
@camelCaseVlad

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 question

Ask a Question

731 491 924 answers to any question