score:1

I think you should not control a component state. Unit tests should be control inputs and outputs.

Like this:

Give status prop true to FormComponent expect .send-user-data button exist.

If you check the Enyzme source code here. You can see instance and class type check. Functional components nodeTypes not equal to class and not have instance.

You can use https://github.com/etiennedi/enzyme-wait for wait for async elements.

Your test can be like this.

Simulate click event .send-user-data button wait(its. setTimeout, promise or xhr) and expect returned user.

score:4

You should avoid testing implementation details. Instead, test if the behavior of the component, when triggering an action which would update your state, acts as you would expect.


Related Query

More Query from same tag