Skip to content

Commit

Permalink
Move hydration error link test
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Sep 24, 2024
1 parent 453fcdc commit 4a7d666
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 21 deletions.
37 changes: 37 additions & 0 deletions test/development/acceptance-app/hydration-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,43 @@ describe('Error overlay for hydration errors in App router', () => {
skipStart: true,
})

it('includes a React docs link when hydration error does occur', async () => {
const { browser } = await sandbox(
next,
new Map([
[
'app/page.js',
outdent`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<main className="child">{isClient ? "client" : "server"}</main>
</div>
);
}
`,
],
]),
'/',
{ pushErrorAsConsoleLog: true }
)

const logs = await browser.log()
expect(logs).toEqual(
expect.arrayContaining([
{
// TODO: Should probably link to https://nextjs.org/docs/messages/react-hydration-error instead.
message: expect.stringContaining(
'https://react.dev/link/hydration-mismatch'
),
source: 'error',
},
])
)
})

it('should show correct hydration error when client and server render different text', async () => {
const { cleanup, session, browser } = await sandbox(
next,
Expand Down
36 changes: 36 additions & 0 deletions test/development/acceptance/hydration-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,42 @@ describe('Error overlay for hydration errors in Pages router', () => {
skipStart: true,
})

it('includes a React docs link when hydration error does occur', async () => {
const { browser } = await sandbox(
next,
new Map([
[
'index.js',
outdent`
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<main className="child">{isClient ? "client" : "server"}</main>
</div>
);
}
`,
],
]),
'/',
{ pushErrorAsConsoleLog: true }
)

const logs = await browser.log()
expect(logs).toEqual(
expect.arrayContaining([
{
// TODO: Should probably link to https://nextjs.org/docs/messages/react-hydration-error instead.
message: expect.stringContaining(
'https://react.dev/link/hydration-mismatch'
),
source: 'error',
},
])
)
})

it('should show correct hydration error when client and server render different text', async () => {
const { cleanup, session, browser } = await sandbox(
next,
Expand Down
4 changes: 0 additions & 4 deletions test/integration/auto-export/pages/[post]/[cmnt].js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ if (typeof window !== 'undefined') {
export default function Page() {
if (typeof window !== 'undefined') {
window.pathnames.push(window.location.pathname)

if (window.location.pathname.includes('hydrate-error')) {
return <p>hydration error</p>
}
}
// eslint-disable-next-line
return <p>{useRouter().asPath}</p>
Expand Down
17 changes: 0 additions & 17 deletions test/integration/auto-export/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,5 @@ describe('Auto Export', () => {
const caughtWarns = await browser.eval(`window.caughtWarns`)
expect(caughtWarns).toEqual([])
})

it('should include error link when hydration error does occur', async () => {
const browser = await webdriver(appPort, '/post-1/hydrate-error', {
pushErrorAsConsoleLog: true,
})
const logs = await browser.log()
expect(logs).toEqual(
expect.arrayContaining([
{
message: expect.stringContaining(
'https://react.dev/link/hydration-mismatch'
),
source: 'error',
},
])
)
})
})
})

0 comments on commit 4a7d666

Please sign in to comment.