- How to Trigger React Error Boundary (Dev and Test)· 4 min read
Trigger a React error boundary by throwing during render, testing the fallback in Jest, and using showBoundary for async or event-handler errors.
- Mock IntersectionObserver in Jest Setup· 5 min read
Fix "IntersectionObserver is not defined" in Jest with a global mock in jest.setup.ts, then trigger isIntersecting to test lazy loading and infinite scroll.
- Fix Jest "window.matchMedia is not a function"· 3 min read
jsdom has no window.matchMedia, so Jest throws a TypeError. Add a plain-function mock to your setup file that survives resetMocks and can match specific queries.
- Fixing Jest Error: 'Not Implemented window.scrollTo'· 2 min read
Fix "Not implemented: window.scrollTo" (or "Window's scrollTo() method" in jsdom 27+) in Jest or Vitest by mocking window.scrollTo in your setup file.
- Fix "ReferenceError: ResizeObserver is not defined" in Jest· 4 min read
Fix "ReferenceError: ResizeObserver is not defined" in Jest or Vitest with a setup-file mock, plus a version that fires the callback so you can test resized layouts.
- Testing Next.js Image Component· 3 min read
Test the Next.js Image component in Jest by mocking next/image as a plain img tag, then assert alt text and src. Includes a component test and common mistakes.
- Testing the next-i18next Library with Jest· 2 min read
Test components that use next-i18next in Jest by mocking useTranslation so t() returns the key. Includes a component test and a global Jest setup file.
- How to Resolve 'Cannot use import statement outside a module' Error when Mocking Swiper JS with Jest· 2 min read
Fix Jest's 'Cannot use import statement outside a module' error with Swiper by letting transformIgnorePatterns transform it, or mock Swiper in unit tests.
- Resolving Jest Error with EMFILE Too Many Open Files· 2 min read
Fix the Jest EMFILE too many open files error by lowering maxWorkers, ignoring build folders, raising ulimit, and running in band on CI.