In this video we will unit-test components that use the Next.js useRouter hook.
We will also see how to have unit-tests side by side with the pages components, without opening new routes for those .spec.tsx files
GitHub URL: https://github.com/bmvantunes/youtube...
Join the channel to support my content:
/ @brunoantunespt
Follow me on:
Twitter: / bmvantunes
Dev.to: https://dev.to/bmvantunes
Website: https://brunoantunes.net
GitHub: https://github.com/bmvantunes
LinkedIn: / bmvantunes
Timeline:
00:00 Introduction
00:06 Why useRouter() is null in unit tests?
02:10 Common online solution to mock useRouter
02:43 Create Mock Router function
04:35 How to unit test useRouter by providing RouterContext Provider
06:48 Link and useRouter unit-test
08:36 Navigate via code, by calling router.push unit test
11:32 Spec files side by side with page components
#jest #ReactTestingLibrary #nextjs
Nesta página do site você pode assistir ao vídeo on-line Unit Testing Next.js Router - useRouter - React.js Testing Tutorial #9 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Bruno Antunes 02 Novembro 2021, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 17,525 vezes e gostou 458 espectadores. Boa visualização!