Unverified Commit c14c6e00 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

test: update test for async client component with snapshot (#74550)

### What

When there's a async client component used in the component tree, it's not available to display the component stack whether you enable react owner stack or not. It's likely a bug in `React.captureOwnerStack`.

We update the existing test here to ensure the error is surfaced when the mistake is comitted. We also assert on the snapshots of component stack but leave it as a TODO now since the component stack of errored component (the async client component) is not displayed.

Related to NDX-475
parent c527168d
'use client'
export default async function Page() {
return <p id="app-router-client-component-value">hello</p>
}
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<html>
<body>{children}</body>
</html>
)
......
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import {
assertNoRedbox,
getRedboxDescription,
getStackFramesContent,
openRedbox,
} from 'next-test-utils'
describe('app-dir - async-client-component', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('app router server component async module', async () => {
const browser = await next.browser('/server')
await assertNoRedbox(browser)
expect(await browser.elementByCss('#app-router-value').text()).toBe('hello')
})
it('app router client component async module', async () => {
const browser = await next.browser('/client')
await openRedbox(browser)
const description = await getRedboxDescription(browser)
const componentStack = await getStackFramesContent(browser)
const result = {
description,
componentStack,
}
// TODO(error): display component stack when react owner stack is available
expect(result).toMatchInlineSnapshot(`
{
"componentStack": "",
"description": "async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding \`'use client'\` to a module that was originally written for the server.",
}
`)
})
})
'use client'
const appValue = await Promise.resolve('hello')
export default function Page() {
return <p id="app-router-client-component-value">{appValue}</p>
}
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
describe('Async modules', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('app router server component async module', async () => {
const browser = await next.browser('/app-router')
expect(await browser.elementByCss('#app-router-value').text()).toBe('hello')
})
// TODO: Investigate/fix issue with React loading async modules failing.
// Rename app/app-router/client-component/skipped-page.tsx to app/app-router/client-component/page.tsx to run this test.
it.skip('app router client component async module', async () => {
const browser = await next.browser('/app-router/client')
expect(
await browser.elementByCss('#app-router-client-component-value').text()
).toBe('hello')
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment