Wk-notes-01-23-test-hook
Bugs from analytic tools
There could be bugs triggered from other lib, like analytics tool glass box. Do NOT spend too much time on it.
Test React Hooks
I invested some time into hooks recently, this is sth I want to share: People says, for custom hooks, it can extract same functionality out as composable logic, so that the logic is more maintainable and testable,but then I found to test it, you will always need to create and mount a Component
over it, because hooks behavior happens ONLY in react component in the vdom. I would say it is testable, but still a bit painful.
So here are 2 snippets I found that can be a conventions we used to test a custom hook:
I. With Customed Component, and simply get things from wrapper.prop
II. Use react-test-hooks lib
A practice from downshiftjs
Get a folder/file structure for each complex hook
Use a testUtil to set up rendering a test component (as always)
Focus on testing hooks funtionality in test.spec.js
Last updated
Was this helpful?