Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for rendering null and undefined in RSC #43768

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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-null-undefined').html()).toBeNull()
jankaifer marked this conversation as resolved.
Show resolved Hide resolved
})

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
}
@@ -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() {}