Unverified Commit c5751fa6 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

fix: next dynamic with jest (#26614)



Fixes #19862

Avoid executing `webpack` property on `loadableGenerated` of loadable component compiled from `next/dynamic` when `require.resolveWeak` is unavailable due to jest runtime missing `require.resolveWeak`.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] unit tests added
parent c2f0653b
...@@ -94,7 +94,8 @@ function createLoadableComponent(loadFn, options) { ...@@ -94,7 +94,8 @@ function createLoadableComponent(loadFn, options) {
if ( if (
!initialized && !initialized &&
typeof window !== 'undefined' && typeof window !== 'undefined' &&
typeof opts.webpack === 'function' typeof opts.webpack === 'function' &&
typeof require.resolveWeak === 'function'
) { ) {
const moduleIds = opts.webpack() const moduleIds = opts.webpack()
READY_INITIALIZERS.push((ids) => { READY_INITIALIZERS.push((ids) => {
......
import React from 'react'
export default function Hello() {
return <div>hello</div>
}
/**
* @jest-environment jsdom
*/
import React from 'react'
import { act, render } from '@testing-library/react'
import dynamic from 'next/dynamic'
describe('next/dynamic', () => {
it('test link with unmount', () => {
const App = dynamic(() => import('./fixtures/stub-components/hello'))
act(() => {
const { unmount } = render(<App />)
unmount()
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment