Skip to content

Commit 8f3ea18

Browse files
committed
fix: next dynamic with jest
1 parent 170dc0d commit 8f3ea18

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

packages/next/build/babel/plugins/react-loadable-plugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import {
3131

3232
import { relative as relativePath } from 'path'
3333

34+
const isTest = process.env.NODE_ENV === 'test'
35+
3436
export default function ({
3537
types: t,
3638
}: {
@@ -166,7 +168,7 @@ export default function ({
166168

167169
if (!dynamicImports.length) return
168170

169-
options.node.properties.push(
171+
!isTest && options.node.properties.push(
170172
t.objectProperty(
171173
t.identifier('loadableGenerated'),
172174
t.objectExpression([
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react'
2+
3+
export default function Hello() {
4+
return <div>hello</div>
5+
}

test/unit/next-dynamic.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
import React from 'react'
5+
import { act, render } from '@testing-library/react'
6+
import dynamic from 'next/dynamic'
7+
8+
describe('next/dynamic', () => {
9+
it('test link with unmount', () => {
10+
const App = dynamic(() => import('./fixtures/stub-components/hello'))
11+
act(() => {
12+
const { unmount } = render(<App />)
13+
unmount()
14+
})
15+
})
16+
})

0 commit comments

Comments
 (0)