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