/
index.test.ts
55 lines (48 loc) · 1.53 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { hasRedbox, renderViaHTTP } from 'next-test-utils'
import webdriver from 'next-webdriver'
const suite =
process.env.NEXT_TEST_REACT_VERSION === '^17' ? describe.skip : describe
// Skip the suspense test if react version is 17
suite('dynamic with suspense', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
import { Suspense } from "react";
import dynamic from "next/dynamic";
const Thing = dynamic(() => import("./thing"), { ssr: false, suspense: true });
export default function IndexPage() {
return (
<div>
<p>Next.js Example</p>
<Suspense fallback="Loading...">
<Thing />
</Suspense>
</div>
);
}
`,
'pages/thing.js': `
export default function Thing() {
return "Thing";
}
`,
},
dependencies: {},
})
})
afterAll(() => next.destroy())
it('should render server-side', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('Next.js Example')
expect(html).toContain('Thing')
})
it('should render client-side', async () => {
const browser = await webdriver(next.url, '/')
expect(await hasRedbox(browser)).toBe(false)
await browser.close()
})
})