Skip to content

Commit

Permalink
Fix react@next and react@experimental tests (#26088)
Browse files Browse the repository at this point in the history
  • Loading branch information
devknoll committed Jun 14, 2021
1 parent 1ebf26a commit 1f09a78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit 1f09a78

Please sign in to comment.