Loading
Current section: Hooks 4 exercises
Problem

Custom Test Components vs Render Hook Utility

Loading exercise

Transcript

00:00 There are a couple of things that I'm not super jazzed about this hook test. And so, I want to show you how to test the hook using a test component. A test component is actually sort of what the render hook utility is doing under the hood,

00:15 but in a way that isn't at all specific to your hook. And so, everything is communicated through this result.current object here. And so, what you can do with a custom test hook is that you can make that, or a test component,

00:34 is you can make that component have all of the UI that is specifically necessary to test your component, or your hook, and you just have like an example use case of how to use your hook, and then you test that component, which will cover your hook. So, I'm showing you both of these because sometimes one makes sense more than the other,

00:54 and there are definitely use cases for both. So, we're going to test this using the test component approach, and you can feel free to make your own decision on which you prefer. And like I said, I prefer them both in different situations, and so that's why we're going to do both. So, have a good time with this one, and we'll see you when you're done.