2021-02-11 19:51:41 +01:00
|
|
|
/**
|
|
|
|
* @jest-environment jsdom
|
|
|
|
*/
|
|
|
|
import { act, render } from '@testing-library/react'
|
|
|
|
import Link from 'next/link'
|
2021-06-14 21:40:15 +02:00
|
|
|
import React from 'react'
|
2021-02-11 19:51:41 +01:00
|
|
|
|
|
|
|
describe('<Link/>', () => {
|
|
|
|
let spy
|
2021-06-14 21:40:15 +02:00
|
|
|
let expectedErrors
|
|
|
|
beforeAll(async () => {
|
2022-04-05 23:51:47 +02:00
|
|
|
spy = jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
|
|
console.log(...args)
|
2021-06-14 21:40:15 +02:00
|
|
|
})
|
2022-04-05 23:51:47 +02:00
|
|
|
|
|
|
|
expectedErrors = 0
|
2021-02-11 19:51:41 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('test link with unmount', () => {
|
|
|
|
act(() => {
|
|
|
|
const { unmount } = render(<Link href="/">hello</Link>)
|
|
|
|
unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-14 21:40:15 +02:00
|
|
|
expect(spy).toHaveBeenCalledTimes(expectedErrors)
|
2021-02-11 19:51:41 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('test link without unmount', () => {
|
|
|
|
act(() => {
|
|
|
|
render(<Link href="/">hello</Link>)
|
|
|
|
})
|
|
|
|
|
2021-06-14 21:40:15 +02:00
|
|
|
expect(spy).toHaveBeenCalledTimes(expectedErrors)
|
2021-02-11 19:51:41 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
spy.mockRestore()
|
|
|
|
})
|
|
|
|
})
|