-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
Copy pathparallel-route-not-found.test.ts
115 lines (97 loc) · 4.21 KB
/
parallel-route-not-found.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { nextTestSetup } from 'e2e-utils'
describe('parallel-route-not-found', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
it('should handle a layout that attempts to render a missing parallel route', async () => {
const browser = await next.browser('/no-bar-slot')
const logs = await browser.log()
expect(await browser.elementByCss('body').text()).toContain(
'This page could not be found'
)
const warnings = logs.filter((log) => log.source === 'warning')
if (isNextDev) {
expect(warnings.length).toBe(1)
expect(warnings[0].message).toContain(
'No default component was found for a parallel route rendered on this page'
)
expect(warnings[0].message).toContain('Missing slots: @bar')
} else {
expect(warnings.length).toBe(0)
}
})
it('should handle multiple missing parallel routes', async () => {
const browser = await next.browser('/both-slots-missing')
const logs = await browser.log()
expect(await browser.elementByCss('body').text()).toContain(
'This page could not be found'
)
const warnings = logs.filter((log) => log.source === 'warning')
if (isNextDev) {
expect(warnings.length).toBe(1)
expect(warnings[0].message).toContain(
'No default component was found for a parallel route rendered on this page'
)
expect(warnings[0].message).toContain('Missing slots: @bar, @foo')
} else {
expect(warnings.length).toBe(0)
}
})
it('should not include any parallel route warnings for a deliberate notFound()', async () => {
const browser = await next.browser('/has-both-slots/not-found-error')
const logs = await browser.log()
expect(await browser.elementByCss('body').text()).toContain(
'This page could not be found'
)
const warnings = logs.filter((log) => log.source === 'warning')
expect(warnings.length).toBe(0)
})
it('should render the page & slots if all parallel routes are found', async () => {
const browser = await next.browser('/has-both-slots')
const logs = await browser.log()
expect(await browser.elementByCss('body').text()).toContain(
'Has Both Slots'
)
expect(await browser.elementByCss('body').text()).toContain('@foo slot')
expect(await browser.elementByCss('body').text()).toContain('@bar slot')
const warnings = logs.filter((log) => log.source === 'warning')
expect(warnings.length).toBe(0)
})
it('should handle `notFound()` in generateMetadata on a page that also renders a parallel route', async () => {
const browser = await next.browser('/not-found-metadata/page-error')
// The page's `generateMetadata` function threw a `notFound()` error,
// so we should see the not found page.
expect(await browser.elementByCss('body').text()).toContain(
'Custom Not Found!'
)
})
it('should handle `notFound()` in a slot', async () => {
const browser = await next.browser('/not-found-metadata/slot-error')
// The page's `generateMetadata` function threw a `notFound()` error,
// so we should see the not found page.
expect(await browser.elementByCss('body').text()).toContain(
'Custom Not Found!'
)
})
// TODO-APP: This test should probably work. But we only provide a not-found boundary for the children slot.
// This means that if a parallel route throws a notFound() in generateMetadata, it won't be properly handled.
it.skip('should handle `notFound()` in a slot with no `children` slot', async () => {
const browser = await next.browser('/not-found-metadata/no-page')
// The page's `generateMetadata` function threw a `notFound()` error,
// so we should see the not found page.
expect(await browser.elementByCss('body').text()).toContain(
'Custom Not Found!'
)
})
if (isNextDev) {
it('should not log any warnings for a regular not found page', async () => {
const browser = await next.browser('/this-page-doesnt-exist')
const logs = await browser.log()
expect(await browser.elementByCss('body').text()).toContain(
'This page could not be found'
)
const warnings = logs.filter((log) => log.source === 'warning')
expect(warnings.length).toBe(0)
})
}
})