question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next.js 9.1.7 Impossible to test next/link with enzyme mount.

See original GitHub issue

Bug 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

  1. yarn install
  2. yarn test
  3. See error

Expected behavior

Should work without error.

System information

  • Version of Next.js: 9.1.7

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:32
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

20reactions
Erazihelcommented, Jan 5, 2020

Got the same error using React Testing Library:

  ● Component › should render correctly

    TypeError: Cannot read property 'pageLoader' of null

       6 | describe("Component", () => {
       7 |   it("should render correctly", () => {
    >  8 |     const { getByText } = render(<Component />);
         |                           ^
       9 |
      10 |     expect(getByText("Hello World")).toBeDefined();
      11 |   });

      at Link.handleRef (packages/header/node_modules/next/dist/client/link.js:8:710)

Component.tsx:

...
            <Link href="/">
              <a className={styles.Link}>Hello World</a>
            </Link>
...

Using Next@9.1.6 does not throw that error.

7reactions
lednhatkhanhcommented, Jan 6, 2020

Facing exact same problem with @testing-library/react

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found