mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
dd5e3ad611
We're starting to use this pattern in more places, so this moves `router-act` into our top level testing utils.
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
import type * as Playwright from 'playwright'
|
|
import { createRouterAct } from 'router-act'
|
|
|
|
describe('<Link prefetch="auto">', () => {
|
|
const { next, isNextDev } = nextTestSetup({
|
|
files: __dirname,
|
|
})
|
|
if (isNextDev) {
|
|
it('disabled in development / deployment', () => {})
|
|
return
|
|
}
|
|
|
|
// NOTE: Since "auto" is just an alias for the default, I'm not bothering to
|
|
// write tests for every default prefetching behavior; that's covered by a
|
|
// bunch of other test suites. This is just a quick test to confirm that the
|
|
// alias exists.
|
|
|
|
it('<Link prefetch="auto"> works the same as if prefetch were undefined or null', async () => {
|
|
// Test that the link only prefetches the static part of the target page
|
|
let page: Playwright.Page
|
|
const browser = await next.browser('/', {
|
|
beforePageLoad(p: Playwright.Page) {
|
|
page = p
|
|
},
|
|
})
|
|
const act = createRouterAct(page)
|
|
|
|
// Reveal the link to trigger a prefetch
|
|
await act(async () => {
|
|
const linkToggle = await browser.elementByCss(
|
|
'input[data-link-accordion="/dynamic"]'
|
|
)
|
|
await linkToggle.click()
|
|
}, [
|
|
// Should prefetch the loading boundary
|
|
{
|
|
includes: 'Loading...',
|
|
},
|
|
// Should not prefetch the dynamic content
|
|
{
|
|
includes: 'Dynamic content',
|
|
block: 'reject',
|
|
},
|
|
])
|
|
|
|
// Navigate to the page
|
|
await act(
|
|
async () => {
|
|
await browser.elementByCss('a[href="/dynamic"]').click()
|
|
},
|
|
{
|
|
// Now the dynamic content should be fetched
|
|
includes: 'Dynamic content',
|
|
}
|
|
)
|
|
})
|
|
})
|