by knuthsat · 4y ago · 0 comments
Although, when I see code snippets on the internet I always wonder how do people test this.
The fact that dependencies are declared as imports and all the logic is inside the component function, it feels like you have to shuffle things around just to make the thing runnable outside of React.
In isolation, unless you have very complex hooks, it’s a bit like you’re testing react or JavaScript themselves. When testing a component which uses the hook, I find you get to test the behaviour and expectations a little better - it’s close to a real use case.
You can find the tests for these hooks here: https://github.com/Molecule-dev/molecule-app/tree/6e2456e216...
Is that what you're asking about?
Of course, you need to write your components in such a way that they are easy to isolate. You can also make use of composition and maybe even mock out components.
Testing the components themselves is ample.