Skip to content

Commit 92b18a9

Browse files
authored
[test] Use new Redbox matchers in app/ hook-functuon-names (#76785)
1 parent 235da18 commit 92b18a9

File tree

1 file changed

+32
-56
lines changed

1 file changed

+32
-56
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { nextTestSetup } from 'e2e-utils'
2-
import { assertHasRedbox, getRedboxSource, openRedbox } from 'next-test-utils'
32

43
describe('hook-function-names', () => {
5-
const { next, isTurbopack } = nextTestSetup({
4+
const { next } = nextTestSetup({
65
files: __dirname,
76
})
87

@@ -11,64 +10,41 @@ describe('hook-function-names', () => {
1110

1211
await browser.elementByCss('button').click()
1312

14-
await openRedbox(browser)
15-
16-
if (isTurbopack) {
17-
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
18-
"app/button/page.tsx (7:11) @ Button.useCallback[handleClick]
19-
20-
5 | const Button = ({ message }: { message: string }) => {
21-
6 | const handleClick = useCallback(() => {
22-
> 7 | throw new Error(message)
23-
| ^
24-
8 | }, [message])
25-
9 |
26-
10 | return ("
27-
`)
28-
} else {
29-
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
30-
"app/button/page.tsx (7:11) @ Button.useCallback[handleClick]
31-
32-
5 | const Button = ({ message }: { message: string }) => {
33-
6 | const handleClick = useCallback(() => {
34-
> 7 | throw new Error(message)
35-
| ^
36-
8 | }, [message])
37-
9 |
38-
10 | return ("
39-
`)
40-
}
13+
await expect(browser).toDisplayCollapsedRedbox(`
14+
{
15+
"count": 1,
16+
"description": "Error: Kaputt!",
17+
"environmentLabel": null,
18+
"label": "Unhandled Runtime Error",
19+
"source": "app/button/page.tsx (7:11) @ Button.useCallback[handleClick]
20+
> 7 | throw new Error(message)
21+
| ^",
22+
"stack": [
23+
"Button.useCallback[handleClick] app/button/page.tsx (7:11)",
24+
"button <anonymous> (0:0)",
25+
"Button app/button/page.tsx (11:5)",
26+
"Page app/button/page.tsx (18:10)",
27+
],
28+
}
29+
`)
4130
})
4231

4332
it('should show readable hook names in stacks for default-exported components', async () => {
4433
const browser = await next.browser('/')
4534

46-
await assertHasRedbox(browser)
47-
48-
if (isTurbopack) {
49-
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
50-
"app/page.tsx (7:11) @ Page.useEffect
51-
52-
5 | export default function Page() {
53-
6 | useEffect(() => {
54-
> 7 | throw new Error('error in useEffect')
55-
| ^
56-
8 | }, [])
57-
9 |
58-
10 | return <p>Hello world!</p>"
59-
`)
60-
} else {
61-
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
62-
"app/page.tsx (7:11) @ Page.useEffect
63-
64-
5 | export default function Page() {
65-
6 | useEffect(() => {
66-
> 7 | throw new Error('error in useEffect')
67-
| ^
68-
8 | }, [])
69-
9 |
70-
10 | return <p>Hello world!</p>"
71-
`)
72-
}
35+
await expect(browser).toDisplayRedbox(`
36+
{
37+
"count": 1,
38+
"description": "Error: error in useEffect",
39+
"environmentLabel": null,
40+
"label": "Unhandled Runtime Error",
41+
"source": "app/page.tsx (7:11) @ Page.useEffect
42+
> 7 | throw new Error('error in useEffect')
43+
| ^",
44+
"stack": [
45+
"Page.useEffect app/page.tsx (7:11)",
46+
],
47+
}
48+
`)
7349
})
7450
})

0 commit comments

Comments
 (0)