Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

worse, it's actually much more difficult to test states in hooks...

it's a variable inside a function -- how am I supposed to test its state from outside (ie. test runner), without resorting to ugly hacks?



You test the hook itself. It is a function after all and using hook testing library, it is fairly easy to test.

And if you want to test the component using it, you simply mock the hook and make sure the mocked hook returns all the value you want to test. What goes inside of the hook is outside your concern when testing the parent component.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: