1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Tests for "ssr: true" on dynamic pages (#5728)

**What's this PR?**
Based on the feedback on [this PR](https://github.com/zeit/next.js/pull/5722) @timneutkens asked me to create a test for `ssr: true`

**What's it do?**

- adds a test for setting `ssr: true` - /basic
- adds a test for setting `ssr: true` - /production
This commit is contained in:
Anderson Leite 2018-11-24 16:11:25 -08:00 committed by Tim Neutkens
parent 9f03fad5e9
commit d6d9dd1e42
4 changed files with 51 additions and 2 deletions

View file

@ -0,0 +1,5 @@
import dynamic from 'next/dynamic'
const Hello = dynamic(import('../../components/hello1'), { ssr: true })
export default Hello

View file

@ -54,7 +54,7 @@ export default (context, render) => {
})
})
describe('ssr:false option', () => {
it('Should render loading on the server side', async () => {
it('should render loading on the server side', async () => {
const $ = await get$('/dynamic/no-ssr')
expect($('body').html()).not.toContain('"dynamicIds"')
expect($('p').text()).toBe('loading...')
@ -73,6 +73,26 @@ export default (context, render) => {
})
})
describe('ssr:true option', () => {
it('Should render the component on the server side', async () => {
const $ = await get$('/dynamic/ssr-true')
expect($('body').html()).toContain('"dynamicIds"')
expect($('p').text()).toBe('Hello World 1')
})
it('should render the component on client side', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/dynamic/ssr-true')
await check(() => browser.elementByCss('body').text(), /Hello World 1/)
} finally {
if (browser) {
browser.close()
}
}
})
})
describe('custom chunkfilename', () => {
it('should render the correct filename', async () => {
const $ = await get$('/dynamic/chunkfilename')

View file

@ -0,0 +1,5 @@
import dynamic from 'next/dynamic'
const Hello = dynamic(import('../../components/hello1'), { ssr: true })
export default Hello

View file

@ -30,7 +30,7 @@ export default (context, render) => {
})
})
describe('ssr:false option', () => {
it('Should render loading on the server side', async () => {
it('should render loading on the server side', async () => {
const $ = await get$('/dynamic/no-ssr')
expect($('p').text()).toBe('loading...')
})
@ -48,6 +48,25 @@ export default (context, render) => {
})
})
describe('ssr:true option', () => {
it('should render the component on the server side', async () => {
const $ = await get$('/dynamic/ssr-true')
expect($('p').text()).toBe('Hello World 1')
})
it('should render the component on client side', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/dynamic/ssr-true')
await check(() => browser.elementByCss('body').text(), /Hello World 1/)
} finally {
if (browser) {
browser.close()
}
}
})
})
describe('custom loading', () => {
it('should render custom loading on the server side when `ssr:false` and `loading` is provided', async () => {
const $ = await get$('/dynamic/no-ssr-custom-loading')