Next.js 9.1.7 Impossible to test next/link with enzyme mount.
See original GitHub issueBug report
Impossible to test next/link with enzyme mount.
Describe the bug
When trying to test a component with next/link using an enzyme mount, an error occurs
Error: Uncaught [TypeError: Cannot read property 'pageLoader' of null].
The error is only in version 9.1.7, in previous versions everything was fine.
To Reproduce
repository to reproduce https://github.com/gudvinga/next-9.1.7-link-jest-enzyme
- yarn install
- yarn test
- See error
Expected behavior
Should work without error.
System information
- Version of Next.js: 9.1.7
Issue Analytics
- State:
- Created 4 years ago
- Reactions:32
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Testing | Next.js
Learn how to set up Next.js with three commonly used testing tools — Cypress, Playwright, Jest, and React Testing Library.
Read more >Mount does not work in enzyme with next js - Stack Overflow
This problem happens because of the version enzyme-adapter-react-16 compared to your react version at 17 that is not compatible.
Read more >Unit Testing intro: JEST and Enzyme, SSR using Next Intro - P12
Day-wise Code: https://drive.google.com/drive/folders/15NK-hDMZiY26tBVtKE-fuufUXwYuZFQT?usp=sharingIn this session, we conclude the entire ...
Read more >Testing Next.js apps with Jest - LogRocket Blog
Jest makes testing large Next.js apps a breeze with automated tests that alert you ... Jest is an amazing, inbuilt tool to test...
Read more >DOM testing Next.js applications - DEV Community
The value provided by Next.js is truly priceless, but there's a missing tile: DOM integration testing (React Testing Library or Enzyme tests, to ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Got the same error using React Testing Library:
Component.tsx:
Using Next@9.1.6 does not throw that error.
Facing exact same problem with
@testing-library/react