Skip to content

Commit

Permalink
Add tests for rendering null and undefined in RSC (#43768)
Browse files Browse the repository at this point in the history
  • Loading branch information
jankaifer committed Dec 7, 2022
1 parent 738de01 commit 08d270c
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/e2e/app-dir/rsc-basic.test.ts
Expand Up @@ -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: {
Expand Down
@@ -0,0 +1,3 @@
export default function Component() {
return null
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/rsc-basic/app/return-null/component/page.js
@@ -0,0 +1,5 @@
import Component from './component'

export default function Page() {
return <Component />
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/rsc-basic/app/return-null/layout.js
@@ -0,0 +1,3 @@
export default function Layout({ children }) {
return <div id="return-null-layout">{children}</div>
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/rsc-basic/app/return-null/layout/layout.js
@@ -0,0 +1,3 @@
export default function Layout() {
return null
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/rsc-basic/app/return-null/layout/page.js
@@ -0,0 +1,3 @@
export default function Page() {
return <div />
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/rsc-basic/app/return-null/page/page.js
@@ -0,0 +1,3 @@
export default function Page() {
return null
}
@@ -0,0 +1 @@
export default function Component() {}
@@ -0,0 +1,5 @@
import Component from './component'

export default function Page() {
return <Component />
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/rsc-basic/app/return-undefined/layout.js
@@ -0,0 +1,3 @@
export default function Layout({ children }) {
return <div id="return-undefined-layout">{children}</div>
}
@@ -0,0 +1 @@
export default function Layout() {}
@@ -0,0 +1,3 @@
export default function Page() {
return <div />
}
@@ -0,0 +1 @@
export default function Page() {}

0 comments on commit 08d270c

Please sign in to comment.