Skip to content

Commit 235da18

Browse files
authored
[test] Use new Redbox matchers in app/ owner-stack-invalid-element-type (#76786)
1 parent 7bac0c4 commit 235da18

File tree

1 file changed

+43
-54
lines changed

1 file changed

+43
-54
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
import { nextTestSetup } from 'e2e-utils'
2-
import {
3-
assertHasRedbox,
4-
getRedboxSource,
5-
getStackFramesContent,
6-
} from 'next-test-utils'
72

83
describe('app-dir - owner-stack-invalid-element-type', () => {
94
const { next } = nextTestSetup({
@@ -13,73 +8,67 @@ describe('app-dir - owner-stack-invalid-element-type', () => {
138
it('should catch invalid element from a browser only component', async () => {
149
const browser = await next.browser('/browser')
1510

16-
await assertHasRedbox(browser)
17-
const source = await getRedboxSource(browser)
11+
await expect(browser).toDisplayRedbox(`
12+
{
13+
"count": 1,
14+
"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.
1815
19-
const stackFramesContent = await getStackFramesContent(browser)
20-
expect(stackFramesContent).toMatchInlineSnapshot(`
21-
"at BrowserOnly (app/browser/browser-only.js (8:7))
22-
at Inner (app/browser/page.js (11:10))
23-
at Page (app/browser/page.js (15:10))"
24-
`)
25-
expect(source).toMatchInlineSnapshot(`
26-
"app/browser/browser-only.js (8:7) @ BrowserOnly
27-
28-
6 | return (
29-
7 | <div>
16+
Check the render method of \`BrowserOnly\`.",
17+
"environmentLabel": null,
18+
"label": "Unhandled Runtime Error",
19+
"source": "app/browser/browser-only.js (8:7) @ BrowserOnly
3020
> 8 | <Foo />
31-
| ^
32-
9 | </div>
33-
10 | )
34-
11 | }"
21+
| ^",
22+
"stack": [
23+
"BrowserOnly app/browser/browser-only.js (8:7)",
24+
"Inner app/browser/page.js (11:10)",
25+
"Page app/browser/page.js (15:10)",
26+
],
27+
}
3528
`)
3629
})
3730

3831
it('should catch invalid element from a rsc component', async () => {
3932
const browser = await next.browser('/rsc')
4033

41-
await assertHasRedbox(browser)
42-
const stackFramesContent = await getStackFramesContent(browser)
43-
const source = await getRedboxSource(browser)
44-
45-
expect(stackFramesContent).toMatchInlineSnapshot(`
46-
"at Inner (app/rsc/page.js (5:10))
47-
at Page (app/rsc/page.js (11:7))"
48-
`)
49-
expect(source).toMatchInlineSnapshot(`
50-
"app/rsc/page.js (5:10) @ Inner
34+
await expect(browser).toDisplayRedbox(`
35+
{
36+
"count": 1,
37+
"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.
5138
52-
3 | // Intermediate component for testing owner stack
53-
4 | function Inner() {
39+
Check the render method of \`Inner\`.",
40+
"environmentLabel": null,
41+
"label": "Unhandled Runtime Error",
42+
"source": "app/rsc/page.js (5:10) @ Inner
5443
> 5 | return <Foo />
55-
| ^
56-
6 | }
57-
7 |
58-
8 | export default function Page() {"
44+
| ^",
45+
"stack": [
46+
"Inner app/rsc/page.js (5:10)",
47+
"Page app/rsc/page.js (11:7)",
48+
],
49+
}
5950
`)
6051
})
6152

6253
it('should catch invalid element from on ssr client component', async () => {
6354
const browser = await next.browser('/ssr')
6455

65-
await assertHasRedbox(browser)
66-
67-
const stackFramesContent = await getStackFramesContent(browser)
68-
const source = await getRedboxSource(browser)
69-
expect(stackFramesContent).toMatchInlineSnapshot(`
70-
"at Inner (app/ssr/page.js (7:10))
71-
at Page (app/ssr/page.js (13:7))"
72-
`)
73-
expect(source).toMatchInlineSnapshot(`
74-
"app/ssr/page.js (7:10) @ Inner
56+
await expect(browser).toDisplayRedbox(`
57+
{
58+
"count": 1,
59+
"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.
7560
76-
5 | // Intermediate component for testing owner stack
77-
6 | function Inner() {
61+
Check the render method of \`Inner\`.",
62+
"environmentLabel": null,
63+
"label": "Unhandled Runtime Error",
64+
"source": "app/ssr/page.js (7:10) @ Inner
7865
> 7 | return <Foo />
79-
| ^
80-
8 | }
81-
9 |
82-
10 | export default function Page() {"
66+
| ^",
67+
"stack": [
68+
"Inner app/ssr/page.js (7:10)",
69+
"Page app/ssr/page.js (13:7)",
70+
],
71+
}
8372
`)
8473
})
8574
})

0 commit comments

Comments
 (0)