Add tests for rendering null and undefined in RSC (#43768)

This commit is contained in:
Jan Kaifer 2022-12-07 12:24:02 +01:00 committed by GitHub
parent 738de0164f
commit 08d270cdeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 73 additions and 0 deletions

View file

@ -64,6 +64,45 @@ describe('app dir - rsc basics', () => {
return
}
it('should correctly render page returning null', async () => {
const homeHTML = await renderViaHTTP(next.url, '/return-null/page')
const $ = cheerio.load(homeHTML)
expect($('#return-null-layout').html()).toBeEmpty()
})
it('should correctly render component returning null', async () => {
const homeHTML = await renderViaHTTP(next.url, '/return-null/component')
const $ = cheerio.load(homeHTML)
expect($('#return-null-layout').html()).toBeEmpty()
})
it('should correctly render layout returning null', async () => {
const homeHTML = await renderViaHTTP(next.url, '/return-null/layout')
const $ = cheerio.load(homeHTML)
expect($('#return-null-layout').html()).toBeEmpty()
})
it('should correctly render page returning undefined', async () => {
const homeHTML = await renderViaHTTP(next.url, '/return-undefined/page')
const $ = cheerio.load(homeHTML)
expect($('#return-undefined-layout').html()).toBeEmpty()
})
it('should correctly render component returning undefined', async () => {
const homeHTML = await renderViaHTTP(
next.url,
'/return-undefined/component'
)
const $ = cheerio.load(homeHTML)
expect($('#return-undefined-layout').html()).toBeEmpty()
})
it('should correctly render layout returning undefined', async () => {
const homeHTML = await renderViaHTTP(next.url, '/return-undefined/layout')
const $ = cheerio.load(homeHTML)
expect($('#return-undefined-layout').html()).toBeEmpty()
})
it('should render server components correctly', async () => {
const homeHTML = await renderViaHTTP(next.url, '/', null, {
headers: {

View file

@ -0,0 +1,3 @@
export default function Component() {
return null
}

View file

@ -0,0 +1,5 @@
import Component from './component'
export default function Page() {
return <Component />
}

View file

@ -0,0 +1,3 @@
export default function Layout({ children }) {
return <div id="return-null-layout">{children}</div>
}

View file

@ -0,0 +1,3 @@
export default function Layout() {
return null
}

View file

@ -0,0 +1,3 @@
export default function Page() {
return <div />
}

View file

@ -0,0 +1,3 @@
export default function Page() {
return null
}

View file

@ -0,0 +1 @@
export default function Component() {}

View file

@ -0,0 +1,5 @@
import Component from './component'
export default function Page() {
return <Component />
}

View file

@ -0,0 +1,3 @@
export default function Layout({ children }) {
return <div id="return-undefined-layout">{children}</div>
}

View file

@ -0,0 +1 @@
export default function Layout() {}

View file

@ -0,0 +1,3 @@
export default function Page() {
return <div />
}

View file

@ -0,0 +1 @@
export default function Page() {}