Files
next.js/test/production/jest/new-link-behavior.test.ts
4588a73542 Convert tests using createNext -> nextTestSetup (#93767)
## What?

Converts existing `createNext()` usage into `nextTestSetup()`. 

`createNext()` was the setup step we had before `nextTestSetup()` was
added.

This PR focused on the simple conversion cases. There will be a
follow-up to complete the last few.

---------

Co-authored-by: Cursor <[email protected]>
2026-05-12 13:16:31 +02:00

51 lines
1.4 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
describe('next/jest newLinkBehavior', () => {
const { next } = nextTestSetup({
files: {
'pages/index.jsx': `
import Link from 'next/link'
export default function Page() {
return <Link href='https://example.com'><div>Hello World!</div></Link>
}
`,
'test/index.test.jsx': `
import { render, screen, act } from '@testing-library/react'
import Page from '../pages/index'
it('Link', () => {
render(<Page />)
const link = screen.getByRole('link', { name: 'Hello World!' })
expect(link.getAttribute('href')).toBe('https://example.com')
})
`,
'jest.config.js': `
const nextJest = require('next/jest')
const createJestConfig = nextJest({ dir: './' })
module.exports = createJestConfig({
testEnvironment: 'jest-environment-jsdom',
})
`,
},
dependencies: {
jest: '29.7.0',
'jest-environment-jsdom': '29.7.0',
'@testing-library/react': '15.0.2',
},
packageJson: {
scripts: {
build: 'next build && jest --forceExit test/index.test.jsx',
},
},
installCommand: 'pnpm i',
skipStart: true,
buildCommand: `pnpm build`,
})
it(`should use new link behavior`, async () => {
await next.start()
})
})