shlogg · Early preview
Peter Jacxsens @lideebe

Front-end developer

Mocking Next Router In React Tests: A Step-by-Step Guide

Mocking `useRouter` from Next.js is crucial when testing React components with Jest. Use `jest.mock` to create a mock, return useful values & test the `push` method separately.

Testing Custom Hooks In React: A Comprehensive Guide

Testing Custom Hooks in React with Jest & Enzyme: Call hook inside functional component, mock dependencies with jest.mock, useSearchParams & useRouter mocks. Example code covers 4 scenarios for testing custom hook behavior.