Skip to content

Commit e942a6a

Browse files
committed
warn -> error for Test Renderer deprecation
We use `console.error` for deprecations. `console.warn` is for less critical issues, like performance anti-patterns.
1 parent b039be6 commit e942a6a

File tree

7 files changed

+26
-36
lines changed

7 files changed

+26
-36
lines changed

packages/internal-test-utils/shouldIgnoreConsoleError.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ module.exports = function shouldIgnoreConsoleError(format, args) {
2323
) !== -1 ||
2424
format.indexOf(
2525
'ReactDOM.hydrate has not been supported since React 18',
26-
) !== -1
26+
) !== -1 ||
27+
format.indexOf('react-test-renderer is deprecated.') !== -1
2728
) {
2829
// We haven't finished migrating our tests to use createRoot.
2930
return true;
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
'use strict';
22

33
module.exports = function shouldIgnoreConsoleWarn(format) {
4-
if (typeof format === 'string') {
5-
if (format.indexOf('Warning: react-test-renderer is deprecated.') === 0) {
6-
return true;
7-
}
8-
}
9-
104
return false;
115
};

packages/react-devtools-shell/src/app/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ignoreErrors([
3131
'Warning: Unsafe lifecycle methods',
3232
'Warning: %s is deprecated in StrictMode.', // findDOMNode
3333
'Warning: ReactDOM.render was removed in React 19',
34+
'Warning: react-test-renderer is deprecated',
3435
]);
3536
ignoreWarnings(['Warning: componentWillReceiveProps has been renamed']);
3637
ignoreLogs([]);

packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let Scheduler;
1919
let ReactDOMServer;
2020
let act;
2121
let assertLog;
22+
let assertConsoleErrorDev;
2223
let waitForAll;
2324
let waitForThrow;
2425

@@ -35,6 +36,7 @@ describe('ReactHooks', () => {
3536

3637
const InternalTestUtils = require('internal-test-utils');
3738
assertLog = InternalTestUtils.assertLog;
39+
assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
3840
waitForAll = InternalTestUtils.waitForAll;
3941
waitForThrow = InternalTestUtils.waitForThrow;
4042
});
@@ -1810,7 +1812,6 @@ describe('ReactHooks', () => {
18101812
// Regression test for #14674
18111813
it('does not swallow original error when updating another component in render phase', async () => {
18121814
const {useState} = React;
1813-
spyOnDev(console, 'error').mockImplementation(() => {});
18141815

18151816
let _setState;
18161817
function A() {
@@ -1837,14 +1838,10 @@ describe('ReactHooks', () => {
18371838
);
18381839
});
18391840
}).rejects.toThrow('Hello');
1840-
1841-
if (__DEV__) {
1842-
expect(console.error).toHaveBeenCalledTimes(1);
1843-
expect(console.error.mock.calls[0][0]).toContain(
1844-
'Warning: Cannot update a component (`%s`) while rendering ' +
1845-
'a different component (`%s`).',
1846-
);
1847-
}
1841+
assertConsoleErrorDev([
1842+
'Warning: Cannot update a component (`A`) while rendering ' +
1843+
'a different component (`B`).',
1844+
]);
18481845
});
18491846

18501847
// Regression test for https://github.com/facebook/react/issues/15057

packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let waitFor;
77
let waitForAll;
88
let waitForThrow;
99
let assertLog;
10+
let assertConsoleErrorDev;
1011
let act;
1112

1213
let fakeModuleCache;
@@ -34,6 +35,7 @@ describe('ReactLazy', () => {
3435
waitForAll = InternalTestUtils.waitForAll;
3536
waitForThrow = InternalTestUtils.waitForThrow;
3637
assertLog = InternalTestUtils.assertLog;
38+
assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
3739
act = InternalTestUtils.act;
3840

3941
fakeModuleCache = new Map();
@@ -205,8 +207,6 @@ describe('ReactLazy', () => {
205207
});
206208

207209
it('does not support arbitrary promises, only module objects', async () => {
208-
spyOnDev(console, 'error').mockImplementation(() => {});
209-
210210
const LazyText = lazy(async () => Text);
211211

212212
const root = ReactTestRenderer.create(null, {
@@ -228,13 +228,11 @@ describe('ReactLazy', () => {
228228

229229
expect(error.message).toMatch('Element type is invalid');
230230
assertLog(['Loading...']);
231+
assertConsoleErrorDev([
232+
'Expected the result of a dynamic import() call',
233+
'Expected the result of a dynamic import() call',
234+
]);
231235
expect(root).not.toMatchRenderedOutput('Hi');
232-
if (__DEV__) {
233-
expect(console.error).toHaveBeenCalledTimes(2);
234-
expect(console.error.mock.calls[0][0]).toContain(
235-
'Expected the result of a dynamic import() call',
236-
);
237-
}
238236
});
239237

240238
it('throws if promise rejects', async () => {

packages/react-test-renderer/src/ReactTestRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ function create(
475475
enableReactTestRendererWarning === true &&
476476
global.IS_REACT_NATIVE_TEST_ENVIRONMENT !== true
477477
) {
478-
console.warn(
478+
console.error(
479479
'react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
480480
);
481481
}

packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,25 @@ describe('ReactTestRenderer', () => {
6060
ReactFeatureFlags.enableReactTestRendererWarning = false;
6161
});
6262

63+
// @gate __DEV__
6364
it('should warn if enableReactTestRendererWarning is enabled', () => {
65+
jest.spyOn(console, 'error').mockImplementation(() => {});
6466
ReactFeatureFlags.enableReactTestRendererWarning = true;
65-
expect(() => {
66-
ReactTestRenderer.create(<div />);
67-
}).toWarnDev(
67+
ReactTestRenderer.create(<div />);
68+
expect(console.error).toHaveBeenCalledTimes(1);
69+
expect(console.error.mock.calls[0][0]).toContain(
6870
'Warning: react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
69-
{withoutStack: true},
7071
);
72+
console.error.mockRestore();
7173
});
7274

73-
// @gate __DEV__
7475
it('should not warn if enableReactTestRendererWarning is enabled but the RN global is set', () => {
76+
jest.spyOn(console, 'error').mockImplementation(() => {});
7577
global.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
7678
ReactFeatureFlags.enableReactTestRendererWarning = true;
77-
expect(() => {
78-
ReactTestRenderer.create(<div />);
79-
}).not.toWarnDev(
80-
'Warning: react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
81-
{withoutStack: true},
82-
);
79+
ReactTestRenderer.create(<div />);
80+
expect(console.error).toHaveBeenCalledTimes(0);
81+
console.error.mockRestore();
8382
});
8483

8584
describe('root tags', () => {

0 commit comments

Comments
 (0)