Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix react@next and react@experimental tests #26088

Merged
merged 3 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test_react_next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
NEXT_TELEMETRY_DISABLED: 1
HEADLESS: true
NEXT_PRIVATE_SKIP_SIZE_TESTS: true
NEXT_PRIVATE_REACT_ROOT: 1
strategy:
fail-fast: false
matrix:
Expand Down
16 changes: 13 additions & 3 deletions test/unit/link-warnings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
*/
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
beforeAll(() => {
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', () => {
Expand All @@ -16,15 +26,15 @@ describe('<Link/>', () => {
unmount()
})

expect(spy).not.toHaveBeenCalled()
expect(spy).toHaveBeenCalledTimes(expectedErrors)
})

it('test link without unmount', () => {
act(() => {
render(<Link href="/">hello</Link>)
})

expect(spy).not.toHaveBeenCalled()
expect(spy).toHaveBeenCalledTimes(expectedErrors)
})

afterAll(() => {
Expand Down