Files
next.js/test/e2e/next-link-errors/next-link-errors.test.ts
Tim NeutkensandGitHub e860cec656 test: migrate webdriver callers to next.browser (#93941)
### What?

Migrate remaining direct `next-webdriver` test callers that have a
`NextInstance` to `next.browser()`, and expose the shared `Playwright`
browser type from `e2e-utils`.

### Why?

`NextInstance.browser` should be the supported browser-opening interface
for test fixtures, with `next-webdriver` kept as the private
implementation detail.

### How?

Updated affected development, e2e, and production tests to call
`next.browser()` directly, passing `baseUrl` where tests intentionally
target a manually spawned or proxied server. Shared helpers now receive
browser callbacks from the test context, and browser types import
`Playwright` from `e2e-utils` instead of deriving from `next.browser` or
importing from private paths.

<!-- NEXT_JS_LLM_PR -->
2026-05-22 14:01:58 +02:00

67 lines
2.2 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
describe('next-link', () => {
const { skipped, next, isNextDev } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) return
it('errors on invalid href', async () => {
const browser = await next.browser('/invalid-href')
if (isNextDev) {
await expect(browser).toDisplayRedbox(`
{
"code": "E319",
"description": "Failed prop type: The prop \`href\` expects a \`string\` or \`object\` in \`<Link>\`, but got \`undefined\` instead.
Open your browser's console to view the Component stack trace.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/invalid-href/page.js (6:10) @ Hello
> 6 | return <Link>Hello, Dave!</Link>
| ^",
"stack": [
"Hello app/invalid-href/page.js (6:10)",
],
}
`)
}
// Client errors show "This page couldn\u2019t load"
expect(await browser.elementByCss('body').text()).toContain(
'This page couldn\u2019t load'
)
})
it('invalid `prefetch` causes runtime error (dev-only)', async () => {
const browser = await next.browser('/invalid-prefetch')
if (isNextDev) {
await expect(browser).toDisplayRedbox(`
{
"code": "E319",
"description": "Failed prop type: The prop \`prefetch\` expects a \`boolean | "auto"\` in \`<Link>\`, but got \`string\` instead.
Open your browser's console to view the Component stack trace.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/invalid-prefetch/page.js (7:5) @ Hello
> 7 | <Link prefetch="unknown" href="https://nextjs.org/">
| ^",
"stack": [
"Hello app/invalid-prefetch/page.js (7:5)",
],
}
`)
// Client errors show "This page couldn\u2019t load"
expect(await browser.elementByCss('body').text()).toContain(
'This page couldn\u2019t load'
)
} else {
expect(await browser.elementByCss('body').text()).toMatchInlineSnapshot(
`"Link with unknown \`prefetch\` renders in prod."`
)
}
})
})