Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Aug 10, 2021
1 parent 2212dcb commit 415f628
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
Expand Up @@ -2,8 +2,8 @@ import { Suspense } from 'react'
import dynamic from 'next/dynamic'

const Hello = dynamic(() => import('./hello'), {
ssr: true,
suspense: true,
ssr: false,
unstable_suspense: false,
})

export default function SuspenseNoSSR({ thrown }) {
Expand Down
39 changes: 8 additions & 31 deletions test/integration/react-18/test/dynamic.js
Expand Up @@ -8,13 +8,13 @@ import { File } from 'next-test-utils'
const appDir = join(__dirname, '../prerelease')
const page = new File(join(appDir, 'components/dynamic-suspense.js'))

function writeDynamicTestComponent({ ssr = false, suspense = false }) {
function writeDynamicTestComponent({ ssr, suspense = false }) {
const content = `import { Suspense } from 'react'
import dynamic from 'next/dynamic'
const Hello = dynamic(() => import('./hello'), {
ssr: ${ssr},
suspense: ${suspense},
${typeof ssr !== 'undefined' ? `ssr: ${ssr},` : ''}
unstable_suspense: ${suspense},
})
export default function SuspenseNoSSR({ thrown }) {
Expand All @@ -34,11 +34,11 @@ export default (context, render) => {
}

describe('suspense:true option', () => {
beforeAll(() => writeDynamicTestComponent({ suspense: true }))
afterAll(() => page.restore())

describe('promise is thrown on server side', () => {
// let `ssr` option be auto overridden
beforeAll(() => writeDynamicTestComponent({ suspense: true }))
afterAll(() => page.restore())

it('should render the fallback on server side', async () => {
const $ = await get$('/suspense/thrown')
const html = $('body').html()
Expand All @@ -62,10 +62,11 @@ export default (context, render) => {
})

describe('promise is not thrown on server side', () => {
// TODO: add case after streaming mode is supported
it('should render fallback on server side', async () => {
const $ = await get$('/suspense/no-thrown')
const text = $('#__next').text()
expect(text).toBe('loading')
expect(text).toContain('loading')
})

it('should hydrate on client side', async () => {
Expand All @@ -81,28 +82,4 @@ export default (context, render) => {
})
})
})

describe('suspense:false option', () => {
beforeAll(() => writeDynamicTestComponent({ suspense: false, ssr: false }))
afterAll(() => page.restore())

it('should render nothing on server side under Suspense', async () => {
const $ = await get$('/suspense/thrown')
const text = $('#__next').text()
expect(text).toBe('')
expect(JSON.parse($('#__NEXT_DATA__').html()).dynamicIds).toBeUndefined()
})

it('should hydrate suspenses on client side with ssr disabled', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/suspense/no-thrown')
await check(() => browser.elementByCss('body').text(), /hello 18/)
} finally {
if (browser) {
await browser.close()
}
}
})
})
}

0 comments on commit 415f628

Please sign in to comment.