Skip to content

Commit

Permalink
Revert "test: Ignore React 18 legacy root deprecation warnings (testi…
Browse files Browse the repository at this point in the history
…ng-library#929)"

This reverts commit c1878a9.
  • Loading branch information
eps1lon committed Sep 11, 2021
1 parent c83a9a4 commit 7887030
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 43 deletions.
19 changes: 5 additions & 14 deletions src/__tests__/cleanup.js
Expand Up @@ -83,10 +83,7 @@ describe('fake timers and missing act warnings', () => {
expect(microTaskSpy).toHaveBeenCalledTimes(0)
// console.error is mocked
// eslint-disable-next-line no-console
expect(console.error).toHaveBeenCalledTimes(
// ReactDOM.render is deprecated in React 18
React.version.startsWith('18') ? 1 : 0,
)
expect(console.error).toHaveBeenCalledTimes(0)
})

test('cleanup does not swallow missing act warnings', () => {
Expand Down Expand Up @@ -118,16 +115,10 @@ describe('fake timers and missing act warnings', () => {
expect(deferredStateUpdateSpy).toHaveBeenCalledTimes(1)
// console.error is mocked
// eslint-disable-next-line no-console
expect(console.error).toHaveBeenCalledTimes(
// ReactDOM.render is deprecated in React 18
React.version.startsWith('18') ? 2 : 1,
)
expect(console.error).toHaveBeenCalledTimes(1)
// eslint-disable-next-line no-console
expect(
console.error.mock.calls[
// ReactDOM.render is deprecated in React 18
React.version.startsWith('18') ? 1 : 0
][0],
).toMatch('a test was not wrapped in act(...)')
expect(console.error.mock.calls[0][0]).toMatch(
'a test was not wrapped in act(...)',
)
})
})
6 changes: 3 additions & 3 deletions src/__tests__/new-act.js
@@ -1,4 +1,4 @@
let asyncAct, consoleErrorMock
let asyncAct

jest.mock('react-dom/test-utils', () => ({
act: cb => {
Expand All @@ -9,11 +9,11 @@ jest.mock('react-dom/test-utils', () => ({
beforeEach(() => {
jest.resetModules()
asyncAct = require('../act-compat').asyncAct
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
jest.spyOn(console, 'error').mockImplementation(() => {})
})

afterEach(() => {
consoleErrorMock.mockRestore()
console.error.mockRestore()
})

test('async act works when it does not exist (older versions of react)', async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/old-act.js
@@ -1,13 +1,13 @@
let asyncAct, consoleErrorMock
let asyncAct

beforeEach(() => {
jest.resetModules()
asyncAct = require('../act-compat').asyncAct
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
jest.spyOn(console, 'error').mockImplementation(() => {})
})

afterEach(() => {
consoleErrorMock.mockRestore()
console.error.mockRestore()
})

jest.mock('react-dom/test-utils', () => ({
Expand Down
5 changes: 1 addition & 4 deletions src/__tests__/stopwatch.js
Expand Up @@ -53,8 +53,5 @@ test('unmounts a component', async () => {
// and get an error.
await sleep(5)
// eslint-disable-next-line no-console
expect(console.error).toHaveBeenCalledTimes(
// ReactDOM.render is deprecated in React 18
React.version.startsWith('18') ? 1 : 0,
)
expect(console.error).not.toHaveBeenCalled()
})
19 changes: 0 additions & 19 deletions tests/setup-env.js
@@ -1,24 +1,5 @@
import '@testing-library/jest-dom/extend-expect'

let consoleErrorMock

beforeEach(() => {
const originalConsoleError = console.error
consoleErrorMock = jest
.spyOn(console, 'error')
.mockImplementation((message, ...optionalParams) => {
// Ignore ReactDOM.render/ReactDOM.hydrate deprecation warning
if (message.indexOf('Use createRoot instead.') !== -1) {
return
}
originalConsoleError(message, ...optionalParams)
})
})

afterEach(() => {
consoleErrorMock.mockRestore()
})

// TODO: Can be removed in a future React release: https://github.com/reactwg/react-18/discussions/23#discussioncomment-798952
// eslint-disable-next-line import/no-extraneous-dependencies -- need the version from React not an explicitly declared one
jest.mock('scheduler', () => require('scheduler/unstable_mock'))

0 comments on commit 7887030

Please sign in to comment.