Commit bf545af7 authored by Jimmy Lai's avatar Jimmy Lai

test: add test for #82456 - layout scripts on 404 page with parallel routes

parent daca04d0
export default function ModalDefault() {
return null
}
export default function ModalPage() {
return null
}
export default function RootLayout({
children,
modal,
}: {
children: React.ReactNode
modal: React.ReactNode
}) {
return (
<html lang="en">
<body>
<script
dangerouslySetInnerHTML={{
__html: 'window.__LAYOUT_SCRIPT_RAN = true',
}}
/>
{children}
{modal}
</body>
</html>
)
}
'use client'
import { useEffect } from 'react'
declare global {
interface Window {
__LAYOUT_SCRIPT_RAN?: boolean
}
}
export function ScriptChecker() {
useEffect(() => {
document.body.setAttribute(
'data-script-ran',
String(!!window.__LAYOUT_SCRIPT_RAN)
)
}, [])
return null
}
import { ScriptChecker } from './not-found-checker'
export default function NotFound() {
return (
<div>
<h1>404 - Not Found</h1>
<ScriptChecker />
</div>
)
}
export default function Home() {
return <p>Home Page</p>
}
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {}
export default nextConfig
import { nextTestSetup } from 'e2e-utils'
describe('parallel-routes-script-not-found', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('layout script should execute on normal page with parallel routes', async () => {
const browser = await next.browser('/')
const result = await browser.eval('window.__LAYOUT_SCRIPT_RAN')
expect(result).toBe(true)
})
it('layout script should execute on 404 page with parallel routes', async () => {
const browser = await next.browser('/nonexistent')
const result = await browser.eval('window.__LAYOUT_SCRIPT_RAN')
expect(result).toBe(true)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment