Compare commits

...

1 Commits

Author SHA1 Message Date
Rick Hanlon
d2b9b1fa18 [tests] remove withoutStack 2026-01-19 12:55:23 -05:00
32 changed files with 656 additions and 773 deletions

View File

@@ -1515,16 +1515,13 @@ describe('ReactFlight', () => {
},
};
const transport = ReactNoopFlightServer.render(<input value={obj} />);
assertConsoleErrorDev(
[
'Only plain objects can be passed to Client Components from Server Components. ' +
'Objects with toJSON methods are not supported. ' +
'Convert it manually to a simple value before passing it to props.\n' +
' <input value={{toJSON: ...}}>\n' +
' ^^^^^^^^^^^^^^^',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Only plain objects can be passed to Client Components from Server Components. ' +
'Objects with toJSON methods are not supported. ' +
'Convert it manually to a simple value before passing it to props.\n' +
' <input value={{toJSON: ...}}>\n' +
' ^^^^^^^^^^^^^^^', {withoutStack: true}],
]);
ReactNoopFlightClient.read(transport);
assertConsoleErrorDev([
@@ -1546,14 +1543,11 @@ describe('ReactFlight', () => {
const transport = ReactNoopFlightServer.render(
<div>Womp womp: {new MyError('spaghetti')}</div>,
);
assertConsoleErrorDev(
[
'Error objects cannot be rendered as text children. Try formatting it using toString().\n' +
' <div>Womp womp: {Error}</div>\n' +
' ^^^^^^^',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Error objects cannot be rendered as text children. Try formatting it using toString().\n' +
' <div>Womp womp: {Error}</div>\n' +
' ^^^^^^^', {withoutStack: true}],
]);
ReactNoopFlightClient.read(transport);
assertConsoleErrorDev([
@@ -1566,15 +1560,12 @@ describe('ReactFlight', () => {
it('should warn in DEV if a special object is passed to a host component', () => {
const transport = ReactNoopFlightServer.render(<input value={Math} />);
assertConsoleErrorDev(
[
'Only plain objects can be passed to Client Components from Server Components. ' +
'Math objects are not supported.\n' +
' <input value={Math}>\n' +
' ^^^^^^',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Only plain objects can be passed to Client Components from Server Components. ' +
'Math objects are not supported.\n' +
' <input value={Math}>\n' +
' ^^^^^^', {withoutStack: true}],
]);
ReactNoopFlightClient.read(transport);
assertConsoleErrorDev([
@@ -1590,15 +1581,12 @@ describe('ReactFlight', () => {
const transport = ReactNoopFlightServer.render(
<input value={{[Symbol.iterator]: {}}} />,
);
assertConsoleErrorDev(
[
'Only plain objects can be passed to Client Components from Server Components. ' +
'Objects with symbol properties like Symbol.iterator are not supported.\n' +
' <input value={{}}>\n' +
' ^^^^',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Only plain objects can be passed to Client Components from Server Components. ' +
'Objects with symbol properties like Symbol.iterator are not supported.\n' +
' <input value={{}}>\n' +
' ^^^^', {withoutStack: true}],
]);
ReactNoopFlightClient.read(transport);
assertConsoleErrorDev([
@@ -1621,16 +1609,13 @@ describe('ReactFlight', () => {
}
const Client = clientReference(ClientImpl);
const transport = ReactNoopFlightServer.render(<Client value={obj} />);
assertConsoleErrorDev(
[
'Only plain objects can be passed to Client Components from Server Components. ' +
'Objects with toJSON methods are not supported. ' +
'Convert it manually to a simple value before passing it to props.\n' +
' <... value={{toJSON: ...}}>\n' +
' ^^^^^^^^^^^^^^^',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Only plain objects can be passed to Client Components from Server Components. ' +
'Objects with toJSON methods are not supported. ' +
'Convert it manually to a simple value before passing it to props.\n' +
' <... value={{toJSON: ...}}>\n' +
' ^^^^^^^^^^^^^^^', {withoutStack: true}],
]);
ReactNoopFlightClient.read(transport);
assertConsoleErrorDev([
@@ -1656,16 +1641,13 @@ describe('ReactFlight', () => {
const transport = ReactNoopFlightServer.render(
<Client>Current date: {obj}</Client>,
);
assertConsoleErrorDev(
[
'Only plain objects can be passed to Client Components from Server Components. ' +
'Objects with toJSON methods are not supported. ' +
'Convert it manually to a simple value before passing it to props.\n' +
' <>Current date: {{toJSON: ...}}</>\n' +
' ^^^^^^^^^^^^^^^',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Only plain objects can be passed to Client Components from Server Components. ' +
'Objects with toJSON methods are not supported. ' +
'Convert it manually to a simple value before passing it to props.\n' +
' <>Current date: {{toJSON: ...}}</>\n' +
' ^^^^^^^^^^^^^^^', {withoutStack: true}],
]);
ReactNoopFlightClient.read(transport);
assertConsoleErrorDev([
@@ -1684,15 +1666,12 @@ describe('ReactFlight', () => {
}
const Client = clientReference(ClientImpl);
const transport = ReactNoopFlightServer.render(<Client value={Math} />);
assertConsoleErrorDev(
[
'Only plain objects can be passed to Client Components from Server Components. ' +
'Math objects are not supported.\n' +
' <... value={Math}>\n' +
' ^^^^^^',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Only plain objects can be passed to Client Components from Server Components. ' +
'Math objects are not supported.\n' +
' <... value={Math}>\n' +
' ^^^^^^', {withoutStack: true}],
]);
ReactNoopFlightClient.read(transport);
assertConsoleErrorDev([
@@ -1713,15 +1692,12 @@ describe('ReactFlight', () => {
const transport = ReactNoopFlightServer.render(
<Client value={{[Symbol.iterator]: {}}} />,
);
assertConsoleErrorDev(
[
'Only plain objects can be passed to Client Components from Server Components. ' +
'Objects with symbol properties like Symbol.iterator are not supported.\n' +
' <... value={{}}>\n' +
' ^^^^',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Only plain objects can be passed to Client Components from Server Components. ' +
'Objects with symbol properties like Symbol.iterator are not supported.\n' +
' <... value={{}}>\n' +
' ^^^^', {withoutStack: true}],
]);
ReactNoopFlightClient.read(transport);

View File

@@ -644,32 +644,40 @@ describe('ReactComponentLifeCycle', () => {
]);
assertConsoleWarnDev(
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your code to use " +
'memoization techniques or move it to static getDerivedStateFromProps. ' +
'Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
{withoutStack: true},
],
[
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your code to use " +
'memoization techniques or move it to static getDerivedStateFromProps. ' +
'Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
{withoutStack: true},
],
[
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
{withoutStack: true},
],
],
{withoutStack: true},
);
});
@@ -710,32 +718,40 @@ describe('ReactComponentLifeCycle', () => {
]);
assertConsoleWarnDev(
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your code to use " +
'memoization techniques or move it to static getDerivedStateFromProps. ' +
'Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
{withoutStack: true},
],
[
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your code to use " +
'memoization techniques or move it to static getDerivedStateFromProps. ' +
'Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
{withoutStack: true},
],
[
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: Component',
{withoutStack: true},
],
],
{withoutStack: true},
);
await act(() => {
@@ -812,22 +828,27 @@ describe('ReactComponentLifeCycle', () => {
]);
assertConsoleWarnDev(
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: AllLegacyLifecycles',
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: AllLegacyLifecycles',
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: AllLegacyLifecycles',
{withoutStack: true},
],
[
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: AllLegacyLifecycles',
{withoutStack: true},
],
],
{withoutStack: true},
);
class WillMount extends React.Component {
@@ -879,15 +900,17 @@ describe('ReactComponentLifeCycle', () => {
]);
assertConsoleWarnDev(
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: WillMountAndUpdate',
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: WillMountAndUpdate',
{withoutStack: true},
],
],
{withoutStack: true},
);
class WillReceiveProps extends React.Component {
@@ -914,20 +937,20 @@ describe('ReactComponentLifeCycle', () => {
]);
assertConsoleWarnDev(
[
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your code to use " +
'memoization techniques or move it to static getDerivedStateFromProps. ' +
'Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: WillReceiveProps',
[
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your code to use " +
'memoization techniques or move it to static getDerivedStateFromProps. ' +
'Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: WillReceiveProps',
{withoutStack: true},
],
],
{
withoutStack: true,
},
);
});
@@ -960,22 +983,27 @@ describe('ReactComponentLifeCycle', () => {
]);
assertConsoleWarnDev(
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: AllLegacyLifecycles',
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: AllLegacyLifecycles',
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: AllLegacyLifecycles',
{withoutStack: true},
],
[
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: AllLegacyLifecycles',
{withoutStack: true},
],
],
{withoutStack: true},
);
class WillMount extends React.Component {
@@ -1025,17 +1053,17 @@ describe('ReactComponentLifeCycle', () => {
]);
assertConsoleWarnDev(
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: WillMountAndUpdate',
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: WillMountAndUpdate',
{withoutStack: true},
],
],
{
withoutStack: true,
},
);
class WillReceiveProps extends React.Component {
@@ -1061,20 +1089,20 @@ describe('ReactComponentLifeCycle', () => {
]);
assertConsoleWarnDev(
[
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your code to use " +
'memoization techniques or move it to static getDerivedStateFromProps. ' +
'Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: WillReceiveProps',
[
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your code to use " +
'memoization techniques or move it to static getDerivedStateFromProps. ' +
'Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: WillReceiveProps',
{withoutStack: true},
],
],
{
withoutStack: true,
},
);
});
@@ -1164,32 +1192,40 @@ describe('ReactComponentLifeCycle', () => {
});
assertConsoleWarnDev(
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: MyComponent',
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your code to use " +
'memoization techniques or move it to static getDerivedStateFromProps. ' +
'Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: MyComponent',
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: MyComponent',
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: MyComponent',
{withoutStack: true},
],
[
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your code to use " +
'memoization techniques or move it to static getDerivedStateFromProps. ' +
'Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: MyComponent',
{withoutStack: true},
],
[
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n\n' +
'Please update the following components: MyComponent',
{withoutStack: true},
],
],
{withoutStack: true},
);
expect(log).toEqual(['componentWillMount', 'UNSAFE_componentWillMount']);
@@ -1490,27 +1526,35 @@ describe('ReactComponentLifeCycle', () => {
});
assertConsoleWarnDev(
[
`componentWillMount has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
[
`componentWillMount has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move code with side effects to componentDidMount, and set initial state in the constructor.
* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.
Please update the following components: MyComponent`,
`componentWillReceiveProps has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
{withoutStack: true},
],
[
`componentWillReceiveProps has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.
Please update the following components: MyComponent`,
`componentWillUpdate has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
{withoutStack: true},
],
[
`componentWillUpdate has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move data fetching code or side effects to componentDidUpdate.
* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.
Please update the following components: MyComponent`,
{withoutStack: true},
],
],
{withoutStack: true},
);
// Dedupe check (update and instantiate new)

View File

@@ -3590,14 +3590,14 @@ describe('ReactDOMFizzServer', () => {
onRecoverableError(error, errorInfo) {
expect(error.digest).toBe('a digest');
expect(errorInfo.digest).toBe(undefined);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
' This property is no longer provided as part of errorInfo but can be accessed as a property' +
' of the Error instance itself.',
{withoutStack: true},
],
{withoutStack: true},
);
]);
},
},
);

View File

@@ -633,14 +633,14 @@ describe('ReactDOMFloat', () => {
</>,
);
await waitForAll([]);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Cannot render a <link> with onLoad or onError listeners outside the main document. ' +
'Try removing onLoad={...} and onError={...} or moving it into the root <head> tag or ' +
'somewhere in the <body>.',
{withoutStack: true},
],
{withoutStack: true},
);
]);
return;
});

View File

@@ -1967,15 +1967,13 @@ describe('ReactDOMForm', () => {
// This triggers a synchronous requestFormReset, and a warning
await act(() => resolveText('Wait 1'));
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'requestFormReset was called outside a transition or action. ' +
'To fix, move to an action, or wrap with startTransition.',
{withoutStack: true},
],
{
withoutStack: true,
},
);
]);
assertLog(['Request form reset']);
// The form was reset even though the action didn't finish.

View File

@@ -1073,24 +1073,24 @@ describe('FragmentRefs', () => {
// Warning when there is no attached observer
fragmentRef.current.unobserveUsing(observer);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'You are calling unobserveUsing() with an observer that is not being observed with this fragment ' +
'instance. First attach the observer with observeUsing()',
{withoutStack: true},
],
{withoutStack: true},
);
]);
// Warning when the attached observer does not match
fragmentRef.current.observeUsing(observer);
fragmentRef.current.unobserveUsing(observer2);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'You are calling unobserveUsing() with an observer that is not being observed with this fragment ' +
'instance. First attach the observer with observeUsing()',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
// @gate enableFragmentRefs && enableFragmentRefsInstanceHandles

View File

@@ -52,13 +52,13 @@ describe('ReactDOMRoot', () => {
const callback = jest.fn();
const root = ReactDOMClient.createRoot(container);
root.render(<div>Hi</div>, callback);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'does not support the second callback argument. ' +
'To execute a side effect after rendering, declare it in a component body with useEffect().',
{withoutStack: true},
],
{withoutStack: true},
);
]);
await waitForAll([]);
expect(callback).not.toHaveBeenCalled();
});
@@ -70,15 +70,13 @@ describe('ReactDOMRoot', () => {
const root = ReactDOMClient.createRoot(container);
root.render(<App />, {});
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'You passed a second argument to root.render(...) but it only accepts ' +
'one argument.',
{withoutStack: true},
],
{
withoutStack: true,
},
);
]);
});
it('warn if a container is passed to root.render(...)', async () => {
@@ -88,16 +86,14 @@ describe('ReactDOMRoot', () => {
const root = ReactDOMClient.createRoot(container);
root.render(<App />, container);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'You passed a container to the second argument of root.render(...). ' +
"You don't need to pass it again since you already passed it to create " +
'the root.',
{withoutStack: true},
],
{
withoutStack: true,
},
);
]);
});
it('warns if a callback parameter is provided to unmount', async () => {
@@ -105,13 +101,13 @@ describe('ReactDOMRoot', () => {
const root = ReactDOMClient.createRoot(container);
root.render(<div>Hi</div>);
root.unmount(callback);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'does not support a callback argument. ' +
'To execute a side effect after rendering, declare it in a component body with useEffect().',
{withoutStack: true},
],
{withoutStack: true},
);
]);
await waitForAll([]);
expect(callback).not.toHaveBeenCalled();
});
@@ -216,14 +212,14 @@ describe('ReactDOMRoot', () => {
it('warns when creating two roots managing the same container', () => {
ReactDOMClient.createRoot(container);
ReactDOMClient.createRoot(container);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'You are calling ReactDOMClient.createRoot() on a container that ' +
'has already been passed to createRoot() before. Instead, call ' +
'root.render() on the existing root instead if you want to update it.',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
it('does not warn when creating second root after first one is unmounted', async () => {
@@ -413,13 +409,13 @@ describe('ReactDOMRoot', () => {
it('warn if no children passed to hydrateRoot', async () => {
ReactDOMClient.hydrateRoot(container);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Must provide initial children as second argument to hydrateRoot. ' +
'Example usage: hydrateRoot(domContainer, <App />)',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
it('warn if JSX passed to createRoot', async () => {
@@ -428,18 +424,16 @@ describe('ReactDOMRoot', () => {
}
ReactDOMClient.createRoot(container, <App />);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'You passed a JSX element to createRoot. You probably meant to call root.render instead. ' +
'Example usage:\n' +
'\n' +
' let root = createRoot(domContainer);\n' +
' root.render(<App />);',
{withoutStack: true},
],
{
withoutStack: true,
},
);
]);
});
it('warns when given a function', () => {
@@ -452,15 +446,15 @@ describe('ReactDOMRoot', () => {
ReactDOM.flushSync(() => {
root.render(Component);
});
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Functions are not valid as a React child. ' +
'This may happen if you return Component instead of <Component /> from render. ' +
'Or maybe you meant to call this function rather than return it.\n' +
' root.render(Component)',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
it('warns when given a symbol', () => {
@@ -469,12 +463,12 @@ describe('ReactDOMRoot', () => {
ReactDOM.flushSync(() => {
root.render(Symbol('foo'));
});
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Symbols are not valid as a React child.\n' +
' root.render(Symbol(foo))',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
});

View File

@@ -323,12 +323,12 @@ describe('ReactIdentity', () => {
</div>,
);
}).toThrowError(new TypeError('prod message'));
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'The provided key is an unsupported type TemporalLike.' +
' This value must be coerced to a string before using it here.',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
});

View File

@@ -606,16 +606,16 @@ describe('ReactDOMServer', () => {
ReactDOMServer.renderToString(<Foo />);
jest.runOnlyPendingTimers();
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Can only update a mounting component. ' +
'This usually means you called setState() outside componentWillMount() on the server. ' +
'This is a no-op.\n' +
'\n' +
'Please check the code for the Foo component.',
{withoutStack: true},
],
{withoutStack: true},
);
]);
const markup = ReactDOMServer.renderToStaticMarkup(<Foo />);
expect(markup).toBe('<div>hello</div>');
@@ -639,16 +639,16 @@ describe('ReactDOMServer', () => {
ReactDOMServer.renderToString(<Baz />);
jest.runOnlyPendingTimers();
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Can only update a mounting component. ' +
'This usually means you called forceUpdate() outside componentWillMount() on the server. ' +
'This is a no-op.\n' +
'\n' +
'Please check the code for the Baz component.',
{withoutStack: true},
],
{withoutStack: true},
);
]);
const markup = ReactDOMServer.renderToStaticMarkup(<Baz />);
expect(markup).toBe('<div></div>');
});

View File

@@ -379,20 +379,20 @@ describe('ReactDOMServerHydration', () => {
});
assertConsoleWarnDev(
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n' +
'\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\n' +
'Please update the following components: ComponentWithWarning',
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n' +
'\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. ' +
'In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, ' +
'you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\n' +
'Please update the following components: ComponentWithWarning',
{withoutStack: true},
],
],
{
withoutStack: true,
},
);
expect(element.textContent).toBe('Hi');
});

View File

@@ -1063,13 +1063,13 @@ describe('ReactUpdates', () => {
'Invalid argument passed as callback. Expected a function. Instead ' +
'received: no',
);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Expected the last optional `callback` argument to be ' +
'a function. Instead received: no.',
{withoutStack: true},
],
{withoutStack: true},
);
]);
container = document.createElement('div');
root = ReactDOMClient.createRoot(container);
await act(() => {
@@ -1084,13 +1084,13 @@ describe('ReactUpdates', () => {
'Invalid argument passed as callback. Expected a function. Instead ' +
'received: [object Object]',
);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Expected the last optional `callback` argument to be ' +
"a function. Instead received: { foo: 'bar' }.",
{withoutStack: true},
],
{withoutStack: true},
);
]);
container = document.createElement('div');
root = ReactDOMClient.createRoot(container);
await act(() => {
@@ -1136,13 +1136,13 @@ describe('ReactUpdates', () => {
'Invalid argument passed as callback. Expected a function. Instead ' +
'received: no',
);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Expected the last optional `callback` argument to be ' +
'a function. Instead received: no.',
{withoutStack: true},
],
{withoutStack: true},
);
]);
container = document.createElement('div');
root = ReactDOMClient.createRoot(container);
await act(() => {
@@ -1157,13 +1157,13 @@ describe('ReactUpdates', () => {
'Invalid argument passed as callback. Expected a function. Instead ' +
'received: [object Object]',
);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Expected the last optional `callback` argument to be ' +
"a function. Instead received: { foo: 'bar' }.",
{withoutStack: true},
],
{withoutStack: true},
);
]);
// Make sure the warning is deduplicated and doesn't fire again
container = document.createElement('div');
root = ReactDOMClient.createRoot(container);

View File

@@ -477,9 +477,9 @@ describe('ReactFabric', () => {
expect(nativeFabricUIManager.dispatchCommand).not.toBeCalled();
ReactFabric.dispatchCommand(viewRef, 'updateCommand', [10, 20]);
assertConsoleErrorDev([DISPATCH_COMMAND_REQUIRES_HOST_COMPONENT], {
withoutStack: true,
});
assertConsoleErrorDev([
[DISPATCH_COMMAND_REQUIRES_HOST_COMPONENT, {withoutStack: true}],
]);
expect(nativeFabricUIManager.dispatchCommand).not.toBeCalled();
});
@@ -542,9 +542,9 @@ describe('ReactFabric', () => {
expect(nativeFabricUIManager.sendAccessibilityEvent).not.toBeCalled();
ReactFabric.sendAccessibilityEvent(viewRef, 'eventTypeName');
assertConsoleErrorDev([SEND_ACCESSIBILITY_EVENT_REQUIRES_HOST_COMPONENT], {
withoutStack: true,
});
assertConsoleErrorDev([
[SEND_ACCESSIBILITY_EVENT_REQUIRES_HOST_COMPONENT, {withoutStack: true}],
]);
expect(nativeFabricUIManager.sendAccessibilityEvent).not.toBeCalled();
});

View File

@@ -219,10 +219,12 @@ describe('act warnings', () => {
act(() => {
setState(1);
});
assertConsoleErrorDev(
['The current testing environment is not configured to support act(...)'],
{withoutStack: true},
);
assertConsoleErrorDev([
[
'The current testing environment is not configured to support act(...)',
{withoutStack: true},
],
]);
assertLog([1]);
expect(root).toMatchRenderedOutput('1');
@@ -240,12 +242,12 @@ describe('act warnings', () => {
act(() => {
setState(1);
});
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'The current testing environment is not configured to support act(...)',
{withoutStack: true},
],
{withoutStack: true},
);
]);
assertLog([1]);
expect(root).toMatchRenderedOutput('1');
});
@@ -255,7 +257,7 @@ describe('act warnings', () => {
await withActEnvironment(true, () => {
const root = ReactNoop.createRoot();
root.render('Hi');
assertConsoleErrorDev(
assertConsoleErrorDev([
[
// TODO: Better error message that doesn't make it look like "Root" is
// the name of a custom component
@@ -270,9 +272,9 @@ describe('act warnings', () => {
'\n' +
"This ensures that you're testing the behavior the user would see in the browser. " +
'Learn more at https://react.dev/link/wrap-tests-with-act',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
});
@@ -374,7 +376,7 @@ describe('act warnings', () => {
// This is a retry, not a ping, because we already showed a fallback.
resolveText('Async');
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'A suspended resource finished loading inside a test, but the event was not wrapped in act(...).\n' +
'\n' +
@@ -387,9 +389,12 @@ describe('act warnings', () => {
'\n' +
"This ensures that you're testing the behavior the user would see in the browser. " +
'Learn more at https://react.dev/link/wrap-tests-with-act',
{withoutStack: true},
],
// pre-warming
// pre-warming
[
'A suspended resource finished loading inside a test, but the event was not wrapped in act(...).\n' +
'\n' +
'When testing, code that resolves suspended data should be wrapped into act(...):\n' +
@@ -401,10 +406,9 @@ describe('act warnings', () => {
'\n' +
"This ensures that you're testing the behavior the user would see in the browser. " +
'Learn more at https://react.dev/link/wrap-tests-with-act',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
});
@@ -437,7 +441,7 @@ describe('act warnings', () => {
// This is a ping, not a retry, because no fallback is showing.
resolveText('Async');
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'A suspended resource finished loading inside a test, but the event was not wrapped in act(...).\n' +
'\n' +
@@ -450,9 +454,9 @@ describe('act warnings', () => {
'\n' +
"This ensures that you're testing the behavior the user would see in the browser. " +
'Learn more at https://react.dev/link/wrap-tests-with-act',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
});
});

View File

@@ -1237,14 +1237,14 @@ describe('ReactAsyncActions', () => {
setLoadingProgress('25%');
startTransition(() => setText('B'));
});
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'An optimistic state update occurred outside a transition or ' +
'action. To fix, move the update to an action, or wrap ' +
'with startTransition.',
{withoutStack: true},
],
{withoutStack: true},
);
]);
assertLog(['Loading... (25%)', 'A', 'B']);
expect(root).toMatchRenderedOutput(<div>B</div>);
});

View File

@@ -244,15 +244,15 @@ describe('ReactHooks', () => {
throw new Error('Expected to ignore the callback.');
}),
);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'State updates from the useState() and useReducer() Hooks ' +
"don't support the second callback argument. " +
'To execute a side effect after rendering, ' +
'declare it in the component body with useEffect().',
{withoutStack: true},
],
{withoutStack: true},
);
]);
assertLog(['Count: 1']);
expect(root).toMatchRenderedOutput('1');
});
@@ -279,15 +279,15 @@ describe('ReactHooks', () => {
throw new Error('Expected to ignore the callback.');
}),
);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'State updates from the useState() and useReducer() Hooks ' +
"don't support the second callback argument. " +
'To execute a side effect after rendering, ' +
'declare it in the component body with useEffect().',
{withoutStack: true},
],
{withoutStack: true},
);
]);
assertLog(['Count: 1']);
expect(root).toMatchRenderedOutput('1');
});

View File

@@ -236,7 +236,7 @@ describe('ReactHooksWithNoopRenderer', () => {
expect(() => useState(0)).toThrow(
"Cannot read property 'useState' of null",
);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for' +
' one of the following reasons:\n' +
@@ -244,9 +244,9 @@ describe('ReactHooksWithNoopRenderer', () => {
'2. You might be breaking the Rules of Hooks\n' +
'3. You might have more than one copy of React in the same app\n' +
'See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
describe('useState', () => {

View File

@@ -375,24 +375,24 @@ describe('memo', () => {
it('warns if the first argument is undefined', () => {
memo();
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'memo: The first argument must be a component. Instead ' +
'received: undefined',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
it('warns if the first argument is null', () => {
memo(null);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'memo: The first argument must be a component. Instead ' +
'received: null',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
it('does not drop lower priority state updates when bailing out at higher pri (simple)', async () => {

View File

@@ -862,14 +862,12 @@ describe('ReactNewContext', () => {
);
await waitForAll([]);
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'The `value` prop is required for the `<Context.Provider>`. Did you misspell it or forget to pass it?',
{withoutStack: true},
],
{
withoutStack: true,
},
);
]);
});
it('warns if multiple renderers concurrently render the same context', async () => {

View File

@@ -1120,20 +1120,20 @@ describe('ReactFlightDOMEdge', () => {
};
ServerModule.greet.bind({}, 'hi');
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Cannot bind "this" of a Server Action. Pass null or undefined as the first argument to .bind().',
{withoutStack: true},
],
{withoutStack: true},
);
]);
ServerModuleImportedOnClient.greet.bind({}, 'hi');
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'Cannot bind "this" of a Server Action. Pass null or undefined as the first argument to .bind().',
{withoutStack: true},
],
{withoutStack: true},
);
]);
});
it('should supports ReadableStreams with typed arrays', async () => {

View File

@@ -38,17 +38,15 @@ describe('ReactTestRenderer', () => {
await act(() => {
ReactTestRenderer.create(ReactDOM.createPortal('foo', container));
}).catch(e => (error = e));
assertConsoleErrorDev(
assertConsoleErrorDev([
[
'An invalid container has been provided. ' +
'This may indicate that another renderer is being used in addition to the test renderer. ' +
'(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' +
'This is not supported.',
{withoutStack: true},
],
{
withoutStack: true,
},
);
]);
// After the update throws, a subsequent render is scheduled to
// unmount the whole tree. This update also causes an error, so React

View File

@@ -539,15 +539,11 @@ describe 'ReactCoffeeScriptClass', ->
expect(-> ref.current.replaceState {}).toThrow()
assertConsoleWarnDev([
'replaceState(...) is deprecated in plain JavaScript React classes.
Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236).'
], {withoutStack: true})
['replaceState(...) is deprecated in plain JavaScript React classes. Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236).', {withoutStack: true}]])
expect(-> ref.current.isMounted()).toThrow()
assertConsoleWarnDev([
'isMounted(...) is deprecated in plain JavaScript React classes.
Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks.',
], {withoutStack: true})
['isMounted(...) is deprecated in plain JavaScript React classes. Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks.', {withoutStack: true}]])
if !featureFlags.disableLegacyContext
it 'supports this.context passed via getChildContext', ->

View File

@@ -84,15 +84,12 @@ describe('ReactCreateElement', () => {
it('should warn when `key` is being accessed on a host element', () => {
const element = React.createElement('div', {key: '3'});
void element.props.key;
assertConsoleErrorDev(
[
'div: `key` is not a prop. Trying to access it will result ' +
'in `undefined` being returned. If you need to access the same ' +
'value within the child component, you should pass it as a different ' +
'prop. (https://react.dev/link/special-props)',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['div: `key` is not a prop. Trying to access it will result ' +
'in `undefined` being returned. If you need to access the same ' +
'value within the child component, you should pass it as a different ' +
'prop. (https://react.dev/link/special-props)', {withoutStack: true}],
]);
});
it('allows a string to be passed as the type', () => {
@@ -151,16 +148,11 @@ describe('ReactCreateElement', () => {
});
expect(element.type).toBe(ComponentClass);
expect(element.ref).toBe(ref);
assertConsoleErrorDev(
[
'Accessing element.ref was removed in React 19. ref is now a ' +
'regular prop. It will be removed from the JSX Element ' +
'type in a future release.',
],
{
withoutStack: true,
},
);
assertConsoleErrorDev([
['Accessing element.ref was removed in React 19. ref is now a ' +
'regular prop. It will be removed from the JSX Element ' +
'type in a future release.', {withoutStack: true}],
]);
const expectation = {foo: '56', ref};
Object.freeze(expectation);
expect(element.props).toEqual(expectation);
@@ -429,16 +421,11 @@ describe('ReactCreateElement', () => {
it('warns if outdated JSX transform is detected', async () => {
// Warns if __self is detected, because that's only passed by a compiler
React.createElement('div', {className: 'foo', __self: this});
assertConsoleWarnDev(
[
'Your app (or one of its dependencies) is using an outdated JSX ' +
'transform. Update to the modern JSX transform for ' +
'faster performance: https://react.dev/link/new-jsx-transform',
],
{
withoutStack: true,
},
);
assertConsoleWarnDev([
['Your app (or one of its dependencies) is using an outdated JSX ' +
'transform. Update to the modern JSX transform for ' +
'faster performance: https://react.dev/link/new-jsx-transform', {withoutStack: true}],
]);
// Only warns the first time. Subsequent elements don't warn.
React.createElement('div', {className: 'foo', __self: this});

View File

@@ -589,22 +589,16 @@ describe('ReactES6Class', () => {
runTest(<Inner name="foo" ref={ref} />, 'DIV', 'foo');
expect(() => ref.current.replaceState({})).toThrow();
assertConsoleWarnDev(
[
'replaceState(...) is deprecated in plain JavaScript React classes. ' +
'Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236).',
],
{withoutStack: true},
);
assertConsoleWarnDev([
['replaceState(...) is deprecated in plain JavaScript React classes. ' +
'Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236).', {withoutStack: true}],
]);
expect(() => ref.current.isMounted()).toThrow();
assertConsoleWarnDev(
[
'isMounted(...) is deprecated in plain JavaScript React classes. ' +
'Instead, make sure to clean up subscriptions and pending requests in ' +
'componentWillUnmount to prevent memory leaks.',
],
{withoutStack: true},
);
assertConsoleWarnDev([
['isMounted(...) is deprecated in plain JavaScript React classes. ' +
'Instead, make sure to clean up subscriptions and pending requests in ' +
'componentWillUnmount to prevent memory leaks.', {withoutStack: true}],
]);
});
if (!require('shared/ReactFeatureFlags').disableLegacyContext) {

View File

@@ -346,16 +346,11 @@ describe('ReactElementClone', () => {
expect(clone.key).toBe('12');
expect(clone.props.ref).toBe('34');
expect(clone.ref).toBe('34');
assertConsoleErrorDev(
[
'Accessing element.ref was removed in React 19. ref is now a ' +
'regular prop. It will be removed from the JSX Element ' +
'type in a future release.',
],
{
withoutStack: true,
},
);
assertConsoleErrorDev([
['Accessing element.ref was removed in React 19. ref is now a ' +
'regular prop. It will be removed from the JSX Element ' +
'type in a future release.', {withoutStack: true}],
]);
expect(clone.props).toEqual({foo: 'ef', ref: '34'});
if (__DEV__) {
expect(Object.isFrozen(element)).toBe(true);

View File

@@ -225,28 +225,22 @@ describe('ReactJSXRuntime', () => {
await act(() => {
root.render(JSXRuntime.jsxs('div', {children: 'foo'}, null));
});
assertConsoleErrorDev(
[
'React.jsx: Static children should always be an array. ' +
'You are likely explicitly calling React.jsxs or React.jsxDEV. ' +
'Use the Babel transform instead.',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['React.jsx: Static children should always be an array. ' +
'You are likely explicitly calling React.jsxs or React.jsxDEV. ' +
'Use the Babel transform instead.', {withoutStack: true}],
]);
});
it('should warn when `key` is being accessed on a host element', () => {
const element = JSXRuntime.jsxs('div', {}, '3');
void element.props.key;
assertConsoleErrorDev(
[
'div: `key` is not a prop. Trying to access it will result ' +
'in `undefined` being returned. If you need to access the same ' +
'value within the child component, you should pass it as a different ' +
'prop. (https://react.dev/link/special-props)',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['div: `key` is not a prop. Trying to access it will result ' +
'in `undefined` being returned. If you need to access the same ' +
'value within the child component, you should pass it as a different ' +
'prop. (https://react.dev/link/special-props)', {withoutStack: true}],
]);
});
it('should warn when unkeyed children are passed to jsx', async () => {
@@ -372,17 +366,14 @@ describe('ReactJSXRuntime', () => {
const elementWithSpreadKey = __DEV__
? JSXDEVRuntime.jsxDEV('div', configWithKey)
: JSXRuntime.jsx('div', configWithKey);
assertConsoleErrorDev(
[
'A props object containing a "key" prop is being spread into JSX:\n' +
' let props = {key: someKey, foo: ..., bar: ...};\n' +
' <div {...props} />\n' +
'React keys must be passed directly to JSX without using spread:\n' +
' let props = {foo: ..., bar: ...};\n' +
' <div key={someKey} {...props} />',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['A props object containing a "key" prop is being spread into JSX:\n' +
' let props = {key: someKey, foo: ..., bar: ...};\n' +
' <div {...props} />\n' +
'React keys must be passed directly to JSX without using spread:\n' +
' let props = {foo: ..., bar: ...};\n' +
' <div key={someKey} {...props} />', {withoutStack: true}],
]);
expect(elementWithSpreadKey.props).not.toBe(configWithKey);
});
});

View File

@@ -114,14 +114,11 @@ describe('ReactJSXTransformIntegration', () => {
const element = <Component ref={ref} foo="56" />;
expect(element.type).toBe(Component);
expect(element.ref).toBe(ref);
assertConsoleErrorDev(
[
'Accessing element.ref was removed in React 19. ref is now a ' +
'regular prop. It will be removed from the JSX Element ' +
'type in a future release.',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Accessing element.ref was removed in React 19. ref is now a ' +
'regular prop. It will be removed from the JSX Element ' +
'type in a future release.', {withoutStack: true}],
]);
const expectation = {foo: '56', ref};
Object.freeze(expectation);
expect(element.props).toEqual(expectation);

View File

@@ -59,14 +59,9 @@ describe('Profiler', () => {
await act(() => {
root.render(<React.Profiler />);
});
assertConsoleErrorDev(
[
'Profiler must specify an "id" of type `string` as a prop. Received the type `undefined` instead.',
],
{
withoutStack: true,
},
);
assertConsoleErrorDev([
['Profiler must specify an "id" of type `string` as a prop. Received the type `undefined` instead.', {withoutStack: true}],
]);
});
}

View File

@@ -61,14 +61,11 @@ describe('ReactStartTransition', () => {
});
});
});
assertConsoleWarnDev(
[
'Detected a large number of updates inside startTransition. ' +
'If this is due to a subscription please re-write it to use React provided hooks. ' +
'Otherwise concurrent mode guarantees are off the table.',
],
{withoutStack: true},
);
assertConsoleWarnDev([
['Detected a large number of updates inside startTransition. ' +
'If this is due to a subscription please re-write it to use React provided hooks. ' +
'Otherwise concurrent mode guarantees are off the table.', {withoutStack: true}],
]);
await act(() => {
triggerHookTransition(() => {
@@ -77,13 +74,10 @@ describe('ReactStartTransition', () => {
});
});
});
assertConsoleWarnDev(
[
'Detected a large number of updates inside startTransition. ' +
'If this is due to a subscription please re-write it to use React provided hooks. ' +
'Otherwise concurrent mode guarantees are off the table.',
],
{withoutStack: true},
);
assertConsoleWarnDev([
['Detected a large number of updates inside startTransition. ' +
'If this is due to a subscription please re-write it to use React provided hooks. ' +
'Otherwise concurrent mode guarantees are off the table.', {withoutStack: true}],
]);
});
});

View File

@@ -624,27 +624,24 @@ describe('Concurrent Mode', () => {
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await act(() => root.render(<StrictRoot />));
assertConsoleErrorDev(
[
`Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
assertConsoleErrorDev([
[`Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move code with side effects to componentDidMount, and set initial state in the constructor.
Please update the following components: App`,
`Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
Please update the following components: App`, {withoutStack: true}],
[`Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state
Please update the following components: Bar, Foo`,
`Using UNSAFE_componentWillUpdate in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
Please update the following components: Bar, Foo`, {withoutStack: true}],
[`Using UNSAFE_componentWillUpdate in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move data fetching code or side effects to componentDidUpdate.
Please update the following components: App`,
],
{withoutStack: true},
);
Please update the following components: App`, {withoutStack: true}],
]);
// Dedupe
await act(() => root.render(<App />));
@@ -684,51 +681,45 @@ Please update the following components: App`,
const root = ReactDOMClient.createRoot(container);
await act(() => root.render(<StrictRoot />));
assertConsoleErrorDev(
[
`Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
assertConsoleErrorDev([
[`Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move code with side effects to componentDidMount, and set initial state in the constructor.
Please update the following components: App`,
`Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
Please update the following components: App`, {withoutStack: true}],
[`Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state
Please update the following components: Child`,
`Using UNSAFE_componentWillUpdate in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
Please update the following components: Child`, {withoutStack: true}],
[`Using UNSAFE_componentWillUpdate in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move data fetching code or side effects to componentDidUpdate.
Please update the following components: App`,
],
{withoutStack: true},
);
assertConsoleWarnDev(
[
`componentWillMount has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
Please update the following components: App`, {withoutStack: true}],
]);
assertConsoleWarnDev([
[`componentWillMount has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move code with side effects to componentDidMount, and set initial state in the constructor.
* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.
Please update the following components: Parent`,
`componentWillReceiveProps has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
Please update the following components: Parent`, {withoutStack: true}],
[`componentWillReceiveProps has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.
Please update the following components: Parent`,
`componentWillUpdate has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
Please update the following components: Parent`, {withoutStack: true}],
[`componentWillUpdate has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.
* Move data fetching code or side effects to componentDidUpdate.
* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.
Please update the following components: Parent`,
],
{withoutStack: true},
);
Please update the following components: Parent`, {withoutStack: true}],
]);
// Dedupe
await act(() => root.render(<StrictRoot />));
});
@@ -753,26 +744,20 @@ Please update the following components: Parent`,
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await act(() => root.render(<StrictRoot foo={true} />));
assertConsoleErrorDev(
[
'Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n\n' +
'Please update the following components: Foo',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n\n' +
'Please update the following components: Foo', {withoutStack: true}],
]);
await act(() => root.render(<StrictRoot foo={false} />));
assertConsoleErrorDev(
[
'Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n\n' +
'Please update the following components: Bar',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n\n' +
'Please update the following components: Bar', {withoutStack: true}],
]);
// Dedupe
await act(() => root.render(<StrictRoot foo={true} />));
@@ -821,19 +806,16 @@ Please update the following components: Parent`,
await act(() => {
root.render(<SyncRoot />);
});
assertConsoleErrorDev(
[
'Using UNSAFE_componentWillReceiveProps in strict mode is not recommended ' +
'and may indicate bugs in your code. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, " +
'refactor your code to use memoization techniques or move it to ' +
'static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state\n\n' +
'Please update the following components: Bar, Foo',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Using UNSAFE_componentWillReceiveProps in strict mode is not recommended ' +
'and may indicate bugs in your code. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, " +
'refactor your code to use memoization techniques or move it to ' +
'static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state\n\n' +
'Please update the following components: Bar, Foo', {withoutStack: true}],
]);
// Dedupe
await act(() => {

View File

@@ -694,22 +694,16 @@ describe('ReactTypeScriptClass', function () {
const ref = React.createRef();
test(React.createElement(Inner, {name: 'foo', ref: ref}), 'DIV', 'foo');
expect(() => ref.current.replaceState({})).toThrow();
assertConsoleWarnDev(
[
'replaceState(...) is deprecated in plain JavaScript React classes. ' +
'Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236).',
],
{withoutStack: true},
);
assertConsoleWarnDev([
['replaceState(...) is deprecated in plain JavaScript React classes. ' +
'Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236).', {withoutStack: true}],
]);
expect(() => ref.current.isMounted()).toThrow();
assertConsoleWarnDev(
[
'isMounted(...) is deprecated in plain JavaScript React classes. ' +
'Instead, make sure to clean up subscriptions and pending requests in ' +
'componentWillUnmount to prevent memory leaks.',
],
{withoutStack: true},
);
assertConsoleWarnDev([
['isMounted(...) is deprecated in plain JavaScript React classes. ' +
'Instead, make sure to clean up subscriptions and pending requests in ' +
'componentWillUnmount to prevent memory leaks.', {withoutStack: true}],
]);
});
if (!ReactFeatureFlags.disableLegacyContext) {

View File

@@ -67,13 +67,10 @@ describe('create-react-class-integration', () => {
return <span>{this.props.prop}</span>;
},
});
assertConsoleErrorDev(
[
'Warning: Component: prop type `prop` is invalid; ' +
'it must be a function, usually from React.PropTypes.',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Warning: Component: prop type `prop` is invalid; ' +
'it must be a function, usually from React.PropTypes.', {withoutStack: true}],
]);
});
it('should warn on invalid context types', () => {
@@ -86,13 +83,10 @@ describe('create-react-class-integration', () => {
return <span>{this.props.prop}</span>;
},
});
assertConsoleErrorDev(
[
'Warning: Component: context type `prop` is invalid; ' +
'it must be a function, usually from React.PropTypes.',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Warning: Component: context type `prop` is invalid; ' +
'it must be a function, usually from React.PropTypes.', {withoutStack: true}],
]);
});
it('should throw on invalid child context types', () => {
@@ -105,12 +99,9 @@ describe('create-react-class-integration', () => {
return <span>{this.props.prop}</span>;
},
});
assertConsoleErrorDev(
[
'Warning: Component: child context type `prop` is invalid; it must be a function, usually from React.PropTypes.',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Warning: Component: child context type `prop` is invalid; it must be a function, usually from React.PropTypes.', {withoutStack: true}],
]);
});
it('should warn when misspelling shouldComponentUpdate', () => {
@@ -122,14 +113,11 @@ describe('create-react-class-integration', () => {
return <div />;
},
});
assertConsoleErrorDev(
[
'Warning: A component has a method called componentShouldUpdate(). Did you ' +
'mean shouldComponentUpdate()? The name is phrased as a question ' +
'because the function is expected to return a value.',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Warning: A component has a method called componentShouldUpdate(). Did you ' +
'mean shouldComponentUpdate()? The name is phrased as a question ' +
'because the function is expected to return a value.', {withoutStack: true}],
]);
createReactClass({
displayName: 'NamedComponent',
@@ -140,14 +128,11 @@ describe('create-react-class-integration', () => {
return <div />;
},
});
assertConsoleErrorDev(
[
'Warning: NamedComponent has a method called componentShouldUpdate(). Did you ' +
'mean shouldComponentUpdate()? The name is phrased as a question ' +
'because the function is expected to return a value.',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Warning: NamedComponent has a method called componentShouldUpdate(). Did you ' +
'mean shouldComponentUpdate()? The name is phrased as a question ' +
'because the function is expected to return a value.', {withoutStack: true}],
]);
});
it('should warn when misspelling componentWillReceiveProps', () => {
@@ -159,13 +144,10 @@ describe('create-react-class-integration', () => {
return <div />;
},
});
assertConsoleErrorDev(
[
'Warning: A component has a method called componentWillRecieveProps(). Did you ' +
'mean componentWillReceiveProps()?',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Warning: A component has a method called componentWillRecieveProps(). Did you ' +
'mean componentWillReceiveProps()?', {withoutStack: true}],
]);
});
it('should warn when misspelling UNSAFE_componentWillReceiveProps', () => {
@@ -177,13 +159,10 @@ describe('create-react-class-integration', () => {
return <div />;
},
});
assertConsoleErrorDev(
[
'Warning: A component has a method called UNSAFE_componentWillRecieveProps(). ' +
'Did you mean UNSAFE_componentWillReceiveProps()?',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Warning: A component has a method called UNSAFE_componentWillRecieveProps(). ' +
'Did you mean UNSAFE_componentWillReceiveProps()?', {withoutStack: true}],
]);
});
it('should throw if a reserved property is in statics', () => {
@@ -348,11 +327,8 @@ describe('create-react-class-integration', () => {
root.render(<Outer />);
});
assertConsoleErrorDev([
[
'Component uses the legacy childContextTypes API which will soon be removed. ' +
'Use React.createContext() instead. (https://react.dev/link/legacy-context)',
{withoutStack: true},
],
'Component uses the legacy childContextTypes API which will soon be removed. ' +
'Use React.createContext() instead. (https://react.dev/link/legacy-context)',
'Component uses the legacy contextTypes API which will soon be removed. ' +
'Use React.createContext() with static contextType instead. (https://react.dev/link/legacy-context)' +
'\n in ReactClassComponent (at **)',
@@ -409,13 +385,10 @@ describe('create-react-class-integration', () => {
});
expect(() => Component()).toThrow();
assertConsoleErrorDev(
[
'Warning: Something is calling a React component directly. Use a ' +
'factory or JSX instead. See: https://fb.me/react-legacyfactory',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['Warning: Something is calling a React component directly. Use a ' +
'factory or JSX instead. See: https://fb.me/react-legacyfactory', {withoutStack: true}],
]);
});
it('replaceState and callback works', async () => {
@@ -635,38 +608,35 @@ describe('create-react-class-integration', () => {
'https://react.dev/link/unsafe-component-lifecycles\n' +
' in Component (at **)',
]);
assertConsoleWarnDev(
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component',
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your " +
'code to use memoization techniques or move it to ' +
'static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component',
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component',
],
{withoutStack: true},
);
assertConsoleWarnDev([
['componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component', {withoutStack: true}],
['componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your " +
'code to use memoization techniques or move it to ' +
'static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component', {withoutStack: true}],
['componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component', {withoutStack: true}],
]);
await act(() => {
root.render(<Component foo={1} />);
});
@@ -707,38 +677,35 @@ describe('create-react-class-integration', () => {
'https://react.dev/link/unsafe-component-lifecycles\n' +
' in Component (at **)',
]);
assertConsoleWarnDev(
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component',
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your " +
'code to use memoization techniques or move it to ' +
'static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component',
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component',
],
{withoutStack: true},
);
assertConsoleWarnDev([
['componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component', {withoutStack: true}],
['componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your " +
'code to use memoization techniques or move it to ' +
'static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component', {withoutStack: true}],
['componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component', {withoutStack: true}],
]);
await act(() => {
const root2 = ReactDOMClient.createRoot(document.createElement('div'));
root2.render(<Component foo={1} />);
@@ -781,38 +748,35 @@ describe('create-react-class-integration', () => {
await act(() => {
root.render(<Component foo="bar" />);
});
assertConsoleWarnDev(
[
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component',
'componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your " +
'code to use memoization techniques or move it to ' +
'static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component',
'componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component',
],
{withoutStack: true},
);
assertConsoleWarnDev([
['componentWillMount has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' +
'* Rename componentWillMount to UNSAFE_componentWillMount to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component', {withoutStack: true}],
['componentWillReceiveProps has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
"* If you're updating state whenever props change, refactor your " +
'code to use memoization techniques or move it to ' +
'static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state\n' +
'* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component', {withoutStack: true}],
['componentWillUpdate has been renamed, and is not recommended for use. ' +
'See https://react.dev/link/unsafe-component-lifecycles for details.\n\n' +
'* Move data fetching code or side effects to componentDidUpdate.\n' +
'* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress ' +
'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' +
'To rename all deprecated lifecycles to their new names, you can run ' +
'`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' +
'\nPlease update the following components: Component', {withoutStack: true}],
]);
expect(log).toEqual(['componentWillMount', 'UNSAFE_componentWillMount']);
log.length = 0;

View File

@@ -78,32 +78,26 @@ describe('forwardRef', () => {
it('should warn if not provided a callback during creation', () => {
React.forwardRef(undefined);
assertConsoleErrorDev(
['forwardRef requires a render function but was given undefined.'],
{withoutStack: true},
);
assertConsoleErrorDev([
['forwardRef requires a render function but was given undefined.', {withoutStack: true}],
]);
React.forwardRef(null);
assertConsoleErrorDev(
['forwardRef requires a render function but was given null.'],
{
withoutStack: true,
},
);
assertConsoleErrorDev([
['forwardRef requires a render function but was given null.', {withoutStack: true}],
]);
React.forwardRef('foo');
assertConsoleErrorDev(
['forwardRef requires a render function but was given string.'],
{withoutStack: true},
);
assertConsoleErrorDev([
['forwardRef requires a render function but was given string.', {withoutStack: true}],
]);
});
it('should warn if no render function is provided', () => {
React.forwardRef();
assertConsoleErrorDev(
['forwardRef requires a render function but was given undefined.'],
{withoutStack: true},
);
assertConsoleErrorDev([
['forwardRef requires a render function but was given undefined.', {withoutStack: true}],
]);
});
it('should warn if the render function provided has defaultProps attributes', () => {
@@ -113,13 +107,10 @@ describe('forwardRef', () => {
renderWithDefaultProps.defaultProps = {};
React.forwardRef(renderWithDefaultProps);
assertConsoleErrorDev(
[
'forwardRef render functions do not support defaultProps. ' +
'Did you accidentally pass a React component?',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['forwardRef render functions do not support defaultProps. ' +
'Did you accidentally pass a React component?', {withoutStack: true}],
]);
});
it('should not warn if the render function provided does not use any parameter', () => {
@@ -132,13 +123,10 @@ describe('forwardRef', () => {
const arityOfOne = props => <div {...props} />;
React.forwardRef(arityOfOne);
assertConsoleErrorDev(
[
'forwardRef render functions accept exactly two parameters: props and ref. ' +
'Did you forget to use the ref parameter?',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['forwardRef render functions accept exactly two parameters: props and ref. ' +
'Did you forget to use the ref parameter?', {withoutStack: true}],
]);
});
it('should not warn if the render function provided use exactly two parameters', () => {
@@ -150,13 +138,10 @@ describe('forwardRef', () => {
const arityOfThree = (props, ref, x) => <div {...props} ref={ref} x={x} />;
React.forwardRef(arityOfThree);
assertConsoleErrorDev(
[
'forwardRef render functions accept exactly two parameters: props and ref. ' +
'Any additional parameter will be undefined.',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['forwardRef render functions accept exactly two parameters: props and ref. ' +
'Any additional parameter will be undefined.', {withoutStack: true}],
]);
});
it('should skip forwardRef in the stack if neither displayName nor name are present', async () => {
@@ -394,13 +379,10 @@ describe('forwardRef', () => {
return null;
}),
);
assertConsoleErrorDev(
[
'forwardRef requires a render function but received a `memo` ' +
'component. Instead of forwardRef(memo(...)), use ' +
'memo(forwardRef(...)).',
],
{withoutStack: true},
);
assertConsoleErrorDev([
['forwardRef requires a render function but received a `memo` ' +
'component. Instead of forwardRef(memo(...)), use ' +
'memo(forwardRef(...)).', {withoutStack: true}],
]);
});
});