TypeError: require.resolveWeak is not a function (jest test)
See original GitHub issueBug 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
- Clone the repo https://github.com/Emiliano-Bucci/jest-with-dynamic-import- (it’s a fork of the repo
with-jest
example) - Run tests
Expected behavior
It should be possible to test components which contains dynamic imported components, or dynamic components itself.
Screenshots
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:
- Created 3 years ago
- Reactions:13
- Comments:7 (4 by maintainers)
Top 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 >
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
Taking a crack at this. Okay as this is my first PR to the core I have some questions on approach:
My approach would be to check for test environment and simply return the component synchronously.
UPDATE: Sorry, the repo wasn’t reachable; now it’s fixed!