Unverified Commit 9855fd7b authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

test: add test for notFound during streaming (#44078)

Add test for notFound case added in #41735
parent 13a9fb99
import { Suspense } from 'react'
import { notFound } from 'next/navigation'
function createSuspenseyComponent(Component, { timeout = 0, expire = 10 }) {
let result
let promise
return function Data() {
if (result) return result
if (!promise)
promise = new Promise((resolve) => {
setTimeout(() => {
result = <Component />
setTimeout(() => {
result = undefined
promise = undefined
}, expire)
resolve()
}, timeout)
})
throw promise
}
}
function NotFound() {
notFound()
return <></>
}
const SuspenseyNotFound = createSuspenseyComponent(NotFound, {
timeout: 300,
})
export default function () {
return (
<div className="suspense">
<Suspense fallback="fallback">
<SuspenseyNotFound />
</Suspense>
</div>
)
}
......@@ -2364,6 +2364,20 @@ createNextDescribe(
.getAttribute('content')
).toBe('noindex')
})
it('should trigger not-found while streaming', async () => {
const initialHtml = await next.render('/not-found/suspense')
expect(initialHtml).not.toContain('noindex')
const browser = await next.browser('/not-found/suspense')
expect(
await browser.waitForElementByCss('#not-found-component').text()
).toBe('Not Found!')
expect(
await browser
.waitForElementByCss('meta[name="robots"]')
.getAttribute('content')
).toBe('noindex')
})
})
describe('bots', () => {
......
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