DEV Community

Discussion on: TDD with MSW for a Custom Fetch React Hook

Collapse
 
sridhar_natuva profile image
sridhar.natuva

This is good. This is pure tests on custom hook. Can you use that custom hook in any component and write a test case for the component.

I am trying to do that, i get undefined from the custom hook on the component.

Can you help me with this scenario.

Thanks.

Collapse
 
mbarzeev profile image
Matti Bar-Zeev

Hi, can you please share some code (on github fir instance) so I can understand more what it is you're trying to do?

Collapse
 
sridhar_natuva profile image
sridhar.natuva

Hi,
Here is the index page and i am getting data from a custom hook that is wrapped by useSWR hook.
Now i want to write tests for index page by mocking the custom hook.(mock service worker can help here ?)
stackblitz.com/edit/nextjs-gcee4q?...

Thread Thread
 
mbarzeev profile image
Matti Bar-Zeev

Well, I think I understand where you struggle with it, so I took the opportunity to write a post about it here - dev.to/mbarzeev/mocking-data-fetch...
Hope this helps :)