Unverified Commit 235da189 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Use new Redbox matchers in app/ owner-stack-invalid-element-type (#76786)

parent 7bac0c49
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import {
assertHasRedbox,
getRedboxSource,
getStackFramesContent,
} from 'next-test-utils'
describe('app-dir - owner-stack-invalid-element-type', () => { describe('app-dir - owner-stack-invalid-element-type', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -13,73 +8,67 @@ describe('app-dir - owner-stack-invalid-element-type', () => { ...@@ -13,73 +8,67 @@ describe('app-dir - owner-stack-invalid-element-type', () => {
it('should catch invalid element from a browser only component', async () => { it('should catch invalid element from a browser only component', async () => {
const browser = await next.browser('/browser') const browser = await next.browser('/browser')
await assertHasRedbox(browser) await expect(browser).toDisplayRedbox(`
const source = await getRedboxSource(browser) {
"count": 1,
"description": "Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
const stackFramesContent = await getStackFramesContent(browser) Check the render method of \`BrowserOnly\`.",
expect(stackFramesContent).toMatchInlineSnapshot(` "environmentLabel": null,
"at BrowserOnly (app/browser/browser-only.js (8:7)) "label": "Unhandled Runtime Error",
at Inner (app/browser/page.js (11:10)) "source": "app/browser/browser-only.js (8:7) @ BrowserOnly
at Page (app/browser/page.js (15:10))"
`)
expect(source).toMatchInlineSnapshot(`
"app/browser/browser-only.js (8:7) @ BrowserOnly
6 | return (
7 | <div>
> 8 | <Foo /> > 8 | <Foo />
| ^ | ^",
9 | </div> "stack": [
10 | ) "BrowserOnly app/browser/browser-only.js (8:7)",
11 | }" "Inner app/browser/page.js (11:10)",
"Page app/browser/page.js (15:10)",
],
}
`) `)
}) })
it('should catch invalid element from a rsc component', async () => { it('should catch invalid element from a rsc component', async () => {
const browser = await next.browser('/rsc') const browser = await next.browser('/rsc')
await assertHasRedbox(browser) await expect(browser).toDisplayRedbox(`
const stackFramesContent = await getStackFramesContent(browser) {
const source = await getRedboxSource(browser) "count": 1,
"description": "Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
expect(stackFramesContent).toMatchInlineSnapshot(`
"at Inner (app/rsc/page.js (5:10))
at Page (app/rsc/page.js (11:7))"
`)
expect(source).toMatchInlineSnapshot(`
"app/rsc/page.js (5:10) @ Inner
3 | // Intermediate component for testing owner stack Check the render method of \`Inner\`.",
4 | function Inner() { "environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "app/rsc/page.js (5:10) @ Inner
> 5 | return <Foo /> > 5 | return <Foo />
| ^ | ^",
6 | } "stack": [
7 | "Inner app/rsc/page.js (5:10)",
8 | export default function Page() {" "Page app/rsc/page.js (11:7)",
],
}
`) `)
}) })
it('should catch invalid element from on ssr client component', async () => { it('should catch invalid element from on ssr client component', async () => {
const browser = await next.browser('/ssr') const browser = await next.browser('/ssr')
await assertHasRedbox(browser) await expect(browser).toDisplayRedbox(`
{
const stackFramesContent = await getStackFramesContent(browser) "count": 1,
const source = await getRedboxSource(browser) "description": "Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
expect(stackFramesContent).toMatchInlineSnapshot(`
"at Inner (app/ssr/page.js (7:10))
at Page (app/ssr/page.js (13:7))"
`)
expect(source).toMatchInlineSnapshot(`
"app/ssr/page.js (7:10) @ Inner
5 | // Intermediate component for testing owner stack Check the render method of \`Inner\`.",
6 | function Inner() { "environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "app/ssr/page.js (7:10) @ Inner
> 7 | return <Foo /> > 7 | return <Foo />
| ^ | ^",
8 | } "stack": [
9 | "Inner app/ssr/page.js (7:10)",
10 | export default function Page() {" "Page app/ssr/page.js (13:7)",
],
}
`) `)
}) })
}) })
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