TypeError: require.resolveWeak is not a function (jest test)

See original GitHub issue

Bug report

Describe the bug

There’s an error when trying to test a component which contains a dynamic imported component. The error i get is TypeError: require.resolveWeak is not a function.

To Reproduce

  1. Clone the repo https://github.com/Emiliano-Bucci/jest-with-dynamic-import- (it’s a fork of the repo with-jest example)
  2. Run tests

Expected behavior

It should be possible to test components which contains dynamic imported components, or dynamic components itself.

Screenshots

image

System information

  • OS: macOS 11.0.1
  • Browser: Chrome 87.0.4280.88
  • Version of Next.js: 10.0.3
  • Version of Node.js: 12.14.1
  • Deployment: Vercel

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:13
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewmclagancommented, Jan 22, 2021

Taking a crack at this. Okay as this is my first PR to the core I have some questions on approach:

  • Is it ok to do a check for test environment?

My approach would be to check for test environment and simply return the component synchronously.

1reaction
Emiliano-Buccicommented, Dec 9, 2020

UPDATE: Sorry, the repo wasn’t reachable; now it’s fixed!

Read more comments on GitHub >

github_iconTop Results From Across the Web

require.resolveWeak is not a function · Discussion #18855 ...
Hi! I've recently (with the latest version of next js) start to face issues during the test (i use jest and ts-jest )...
Read more >
How to unit test Next.js dynamic components? - Stack Overflow
First jest is failing to compile dynamic imports properly ( require.resolveWeak is not a function - seems to be added by next babel...
Read more >
How to resolve “TypeError: require.context is not a function” in ...
While we were writing Jest tests, we ran into an the error “TypeError: require.context is not a function”. This is because of the...
Read more >
Jest + React Loadable Error Not Supported - ADocLib
First jest is failing to compile dynamic imports properly ( require.resolveWeak is not a function - seems to be added by. In the...
Read more >
Testing in Next.js: Dynamic Imports by sergiodxa
Let's write a simple test for our component. import { render, waitForElement } from "@testing-library/react"; import "@testing-library/jest-dom/extend- ...
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