Skip to content

Commit 7887030

Browse files
committed
Revert "test: Ignore React 18 legacy root deprecation warnings (testing-library#929)"
This reverts commit c1878a9.
1 parent c83a9a4 commit 7887030

File tree

5 files changed

+12
-43
lines changed

5 files changed

+12
-43
lines changed

src/__tests__/cleanup.js

+5-14
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ describe('fake timers and missing act warnings', () => {
8383
expect(microTaskSpy).toHaveBeenCalledTimes(0)
8484
// console.error is mocked
8585
// eslint-disable-next-line no-console
86-
expect(console.error).toHaveBeenCalledTimes(
87-
// ReactDOM.render is deprecated in React 18
88-
React.version.startsWith('18') ? 1 : 0,
89-
)
86+
expect(console.error).toHaveBeenCalledTimes(0)
9087
})
9188

9289
test('cleanup does not swallow missing act warnings', () => {
@@ -118,16 +115,10 @@ describe('fake timers and missing act warnings', () => {
118115
expect(deferredStateUpdateSpy).toHaveBeenCalledTimes(1)
119116
// console.error is mocked
120117
// eslint-disable-next-line no-console
121-
expect(console.error).toHaveBeenCalledTimes(
122-
// ReactDOM.render is deprecated in React 18
123-
React.version.startsWith('18') ? 2 : 1,
124-
)
118+
expect(console.error).toHaveBeenCalledTimes(1)
125119
// eslint-disable-next-line no-console
126-
expect(
127-
console.error.mock.calls[
128-
// ReactDOM.render is deprecated in React 18
129-
React.version.startsWith('18') ? 1 : 0
130-
][0],
131-
).toMatch('a test was not wrapped in act(...)')
120+
expect(console.error.mock.calls[0][0]).toMatch(
121+
'a test was not wrapped in act(...)',
122+
)
132123
})
133124
})

src/__tests__/new-act.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let asyncAct, consoleErrorMock
1+
let asyncAct
22

33
jest.mock('react-dom/test-utils', () => ({
44
act: cb => {
@@ -9,11 +9,11 @@ jest.mock('react-dom/test-utils', () => ({
99
beforeEach(() => {
1010
jest.resetModules()
1111
asyncAct = require('../act-compat').asyncAct
12-
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
12+
jest.spyOn(console, 'error').mockImplementation(() => {})
1313
})
1414

1515
afterEach(() => {
16-
consoleErrorMock.mockRestore()
16+
console.error.mockRestore()
1717
})
1818

1919
test('async act works when it does not exist (older versions of react)', async () => {

src/__tests__/old-act.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
let asyncAct, consoleErrorMock
1+
let asyncAct
22

33
beforeEach(() => {
44
jest.resetModules()
55
asyncAct = require('../act-compat').asyncAct
6-
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
6+
jest.spyOn(console, 'error').mockImplementation(() => {})
77
})
88

99
afterEach(() => {
10-
consoleErrorMock.mockRestore()
10+
console.error.mockRestore()
1111
})
1212

1313
jest.mock('react-dom/test-utils', () => ({

src/__tests__/stopwatch.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,5 @@ test('unmounts a component', async () => {
5353
// and get an error.
5454
await sleep(5)
5555
// eslint-disable-next-line no-console
56-
expect(console.error).toHaveBeenCalledTimes(
57-
// ReactDOM.render is deprecated in React 18
58-
React.version.startsWith('18') ? 1 : 0,
59-
)
56+
expect(console.error).not.toHaveBeenCalled()
6057
})

tests/setup-env.js

-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
import '@testing-library/jest-dom/extend-expect'
22

3-
let consoleErrorMock
4-
5-
beforeEach(() => {
6-
const originalConsoleError = console.error
7-
consoleErrorMock = jest
8-
.spyOn(console, 'error')
9-
.mockImplementation((message, ...optionalParams) => {
10-
// Ignore ReactDOM.render/ReactDOM.hydrate deprecation warning
11-
if (message.indexOf('Use createRoot instead.') !== -1) {
12-
return
13-
}
14-
originalConsoleError(message, ...optionalParams)
15-
})
16-
})
17-
18-
afterEach(() => {
19-
consoleErrorMock.mockRestore()
20-
})
21-
223
// TODO: Can be removed in a future React release: https://github.com/reactwg/react-18/discussions/23#discussioncomment-798952
234
// eslint-disable-next-line import/no-extraneous-dependencies -- need the version from React not an explicitly declared one
245
jest.mock('scheduler', () => require('scheduler/unstable_mock'))

0 commit comments

Comments
 (0)