I was wondering how to test a state change of functional components with the useState
hook with Enzyme. Usually the test would be something along the lines of expect(wrapper.state()).toEqual(expectedState)
but I get the error:
ReactWrapper::state() can only be called on class components
I know that Hooks are still in the alpha stage and things like shallow
still don't work but I was wondering is there a way to this yet?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With