forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink-warnings.test.js
43 lines (36 loc) · 1 KB
/
link-warnings.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @jest-environment jsdom
*/
import { act, render } from '@testing-library/react'
import Link from 'next/link'
import React from 'react'
import { getPackageVersion } from 'next/dist/lib/get-package-version'
import semver from 'next/dist/compiled/semver'
describe('<Link/>', () => {
let spy
let expectedErrors
beforeAll(async () => {
spy = jest.spyOn(console, 'error').mockImplementation(() => {})
const reactVersion = await getPackageVersion({
cwd: __dirname,
name: 'react-dom',
})
expectedErrors = reactVersion && semver.gte(reactVersion, '18.0.0') ? 1 : 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()
})
})