-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
Copy pathnext-link-errors.test.ts
89 lines (81 loc) · 3.51 KB
/
next-link-errors.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { nextTestSetup } from 'e2e-utils'
import webdriver from 'next-webdriver'
describe('next-link', () => {
const { skipped, next, isNextDev } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) return
it('errors on invalid href', async () => {
const browser = await webdriver(next.appPort, '/invalid-href')
if (isNextDev) {
// TODO(veil): https://linear.app/vercel/issue/NDX-554/hide-the-anonymous-frames-which-are-between-2-ignored-frames
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Failed prop type: The prop \`href\` expects a \`string\` or \`object\` in \`<Link>\`, but got \`undefined\` instead.
Open your browser's console to view the Component stack trace.",
"environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "app/invalid-href/page.js (6:10) @ Hello
> 6 | return <Link>Hello, Dave!</Link>
| ^",
"stack": [
"Array.forEach <anonymous> (0:0)",
"Hello app/invalid-href/page.js (6:10)",
],
}
`)
}
expect(await browser.elementByCss('body').text()).toMatchInlineSnapshot(
`"Application error: a client-side exception has occurred while loading localhost (see the browser console for more information)."`
)
})
it('no children', async () => {
const browser = await webdriver(next.appPort, '/no-children')
if (isNextDev) {
// TODO(veil): https://linear.app/vercel/issue/NDX-554/hide-the-anonymous-frames-which-are-between-2-ignored-frames
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: No children were passed to <Link> with \`href\` of \`/about\` but one child is required https://nextjs.org/docs/messages/link-no-children",
"environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "app/no-children/page.js (7:10) @ Page
> 7 | return <Link href="/about" legacyBehavior></Link>
| ^",
"stack": [
"Page app/no-children/page.js (7:10)",
],
}
`)
}
expect(await browser.elementByCss('body').text()).toMatchInlineSnapshot(
`"Application error: a client-side exception has occurred while loading localhost (see the browser console for more information)."`
)
})
it('multiple children', async () => {
const browser = await webdriver(next.appPort, '/multiple-children')
if (isNextDev) {
// TODO(veil): https://linear.app/vercel/issue/NDX-554/hide-the-anonymous-frames-which-are-between-2-ignored-frames
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Multiple children were passed to <Link> with \`href\` of \`/\` but only one child is supported https://nextjs.org/docs/messages/link-multiple-children
Open your browser's console to view the Component stack trace.",
"environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "app/multiple-children/page.js (7:5) @ Index
> 7 | <Link href="/" legacyBehavior>
| ^",
"stack": [
"Index app/multiple-children/page.js (7:5)",
],
}
`)
}
expect(await browser.elementByCss('body').text()).toMatchInlineSnapshot(
`"Application error: a client-side exception has occurred while loading localhost (see the browser console for more information)."`
)
})
})