Unit Testing Next.js Router - useRouter - React.js Testing Tutorial #9

Pubblicato il: 02 novembre 2021
sul canale di: Bruno Antunes
17,525
458

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


In questa pagina del sito puoi guardare il video online Unit Testing Next.js Router - useRouter - React.js Testing Tutorial #9 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Bruno Antunes 02 novembre 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 17,525 volte e gli è piaciuto 458 spettatori. Buona visione!