Skip to content

Commit d6b0ab2

Browse files
committed
Move hydration error link test
1 parent f9de607 commit d6b0ab2

File tree

4 files changed

+73
-21
lines changed

4 files changed

+73
-21
lines changed

test/development/acceptance-app/hydration-error.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,43 @@ describe('Error overlay for hydration errors in App router', () => {
1313
skipStart: true,
1414
})
1515

16+
it('includes a React docs link when hydration error does occur', async () => {
17+
const { browser } = await sandbox(
18+
next,
19+
new Map([
20+
[
21+
'app/page.js',
22+
outdent`
23+
'use client'
24+
const isClient = typeof window !== 'undefined'
25+
export default function Mismatch() {
26+
return (
27+
<div className="parent">
28+
<main className="child">{isClient ? "client" : "server"}</main>
29+
</div>
30+
);
31+
}
32+
`,
33+
],
34+
]),
35+
'/',
36+
{ pushErrorAsConsoleLog: true }
37+
)
38+
39+
const logs = await browser.log()
40+
expect(logs).toEqual(
41+
expect.arrayContaining([
42+
{
43+
// TODO: Should probably link to https://nextjs.org/docs/messages/react-hydration-error instead.
44+
message: expect.stringContaining(
45+
'https://react.dev/link/hydration-mismatch'
46+
),
47+
source: 'error',
48+
},
49+
])
50+
)
51+
})
52+
1653
it('should show correct hydration error when client and server render different text', async () => {
1754
const { cleanup, session, browser } = await sandbox(
1855
next,

test/development/acceptance/hydration-error.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,42 @@ describe('Error overlay for hydration errors in Pages router', () => {
1313
skipStart: true,
1414
})
1515

16+
it('includes a React docs link when hydration error does occur', async () => {
17+
const { browser } = await sandbox(
18+
next,
19+
new Map([
20+
[
21+
'index.js',
22+
outdent`
23+
const isClient = typeof window !== 'undefined'
24+
export default function Mismatch() {
25+
return (
26+
<div className="parent">
27+
<main className="child">{isClient ? "client" : "server"}</main>
28+
</div>
29+
);
30+
}
31+
`,
32+
],
33+
]),
34+
'/',
35+
{ pushErrorAsConsoleLog: true }
36+
)
37+
38+
const logs = await browser.log()
39+
expect(logs).toEqual(
40+
expect.arrayContaining([
41+
{
42+
// TODO: Should probably link to https://nextjs.org/docs/messages/react-hydration-error instead.
43+
message: expect.stringContaining(
44+
'https://react.dev/link/hydration-mismatch'
45+
),
46+
source: 'error',
47+
},
48+
])
49+
)
50+
})
51+
1652
it('should show correct hydration error when client and server render different text', async () => {
1753
const { cleanup, session, browser } = await sandbox(
1854
next,

test/integration/auto-export/pages/[post]/[cmnt].js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ if (typeof window !== 'undefined') {
1818
export default function Page() {
1919
if (typeof window !== 'undefined') {
2020
window.pathnames.push(window.location.pathname)
21-
22-
if (window.location.pathname.includes('hydrate-error')) {
23-
return <p>hydration error</p>
24-
}
2521
}
2622
// eslint-disable-next-line
2723
return <p>{useRouter().asPath}</p>

test/integration/auto-export/test/index.test.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,5 @@ describe('Auto Export', () => {
8989
const caughtWarns = await browser.eval(`window.caughtWarns`)
9090
expect(caughtWarns).toEqual([])
9191
})
92-
93-
it('should include error link when hydration error does occur', async () => {
94-
const browser = await webdriver(appPort, '/post-1/hydrate-error', {
95-
pushErrorAsConsoleLog: true,
96-
})
97-
const logs = await browser.log()
98-
expect(logs).toEqual(
99-
expect.arrayContaining([
100-
{
101-
message: expect.stringContaining(
102-
'https://react.dev/link/hydration-mismatch'
103-
),
104-
source: 'error',
105-
},
106-
])
107-
)
108-
})
10992
})
11093
})

0 commit comments

Comments
 (0)