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
На этой странице сайта вы можете посмотреть видео онлайн Unit Testing Next.js Router - useRouter - React.js Testing Tutorial #9 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Bruno Antunes 02 Ноябрь 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 17,525 раз и оно понравилось 458 зрителям. Приятного просмотра!