mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
## 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]>
51 lines
1.4 KiB
TypeScript
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()
|
|
})
|
|
})
|