mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
We aren't using `'@testing-library/jest-dom'` in 99% of the tests, so there's no point loading it for every test. I've removed it from `jest-setup-after-env` and added the import manually to each file that uses it.
41 lines
819 B
TypeScript
41 lines
819 B
TypeScript
/**
|
|
* @jest-environment jsdom
|
|
*/
|
|
import { act, render } from '@testing-library/react'
|
|
import '@testing-library/jest-dom'
|
|
import Link from 'next/link'
|
|
import React from 'react'
|
|
|
|
describe('<Link/>', () => {
|
|
let spy
|
|
let expectedErrors
|
|
beforeAll(async () => {
|
|
spy = jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
console.log(...args)
|
|
})
|
|
|
|
expectedErrors = 0
|
|
})
|
|
|
|
it('test link with unmount', () => {
|
|
act(() => {
|
|
const { unmount } = render(<Link href="/">hello</Link>)
|
|
unmount()
|
|
})
|
|
|
|
expect(spy).toHaveBeenCalledTimes(expectedErrors)
|
|
})
|
|
|
|
it('test link without unmount', () => {
|
|
act(() => {
|
|
render(<Link href="/">hello</Link>)
|
|
})
|
|
|
|
expect(spy).toHaveBeenCalledTimes(expectedErrors)
|
|
})
|
|
|
|
afterAll(() => {
|
|
spy.mockRestore()
|
|
})
|
|
})
|