Closed akexinad closed 4 years ago
Sorry for the late reply. You are trying to create a sort of integration test, so I suggest you follow best practices by mounting the component and observing the side effects instead of trying to get the actions and manually trigger them on a shallow wrapper.
Another thing I you could do is using dependency replacement to test Fizz
in isolation, independently from the actual useBuzzStore
implementation: have a look at https://github.com/albertogasparin/react-magnetic-di as a nice solution to achieve that
There isn't much documentation on how to test a particular action call and see how it affects the way the component renders.
Example:
Below I have a
Fizz.tsx
component that calls an action inside useEffect:This is my store:
Basically if
state.foo
is greater than zero, the component renders an h2 withstate.foo
's value. If it's zero it renders nothing.How would test this within jest and enzyme in a way where I can invoke the action from within the test and then write an assertion like:
Link to the codesandbox: https://codesandbox.io/s/zen-greider-hohdt