Skip to content

Commit

Permalink
Ignore both versions in DevTools test that might assert on multiple R…
Browse files Browse the repository at this point in the history
…eact
  • Loading branch information
sebmarkbage committed Jun 10, 2024
1 parent 5d7b147 commit 0364e97
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2551,7 +2551,7 @@ describe('InspectedElement', () => {
};

await withErrorsOrWarningsIgnored(
['Warning: Each child in a list should have a unique "key" prop.'],
['Each child in a list should have a unique "key" prop.'],
async () => {
await utils.actAsync(() =>
render(<Example repeatWarningCount={1} />),
Expand Down
21 changes: 10 additions & 11 deletions packages/react-devtools-shared/src/__tests__/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,22 @@ beforeEach(() => {

const originalConsoleError = console.error;
console.error = (...args) => {
const firstArg = args[0];
if (
firstArg === 'Warning: React instrumentation encountered an error: %s'
) {
let firstArg = args[0];
if (typeof firstArg === 'string' && firstArg.startsWith('Warning: ')) {
// Older React versions might use the Warning: prefix. I'm not sure
// if they use this code path.
firstArg = firstArg.slice(9);
}
if (firstArg === 'React instrumentation encountered an error: %s') {
// Rethrow errors from React.
throw args[1];
} else if (
typeof firstArg === 'string' &&
(firstArg.startsWith(
"Warning: It looks like you're using the wrong act()",
) ||
(firstArg.startsWith("It looks like you're using the wrong act()") ||
firstArg.startsWith(
'Warning: The current testing environment is not configured to support act',
'The current testing environment is not configured to support act',
) ||
firstArg.startsWith(
'Warning: You seem to have overlapping act() calls',
))
firstArg.startsWith('You seem to have overlapping act() calls'))
) {
// DevTools intentionally wraps updates with acts from both DOM and test-renderer,
// since test updates are expected to impact both renderers.
Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/src/__tests__/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,7 @@ describe('Store', () => {
}

withErrorsOrWarningsIgnored(
['Warning: Each child in a list should have a unique "key" prop'],
['Each child in a list should have a unique "key" prop'],
() => {
act(() => render(<Example />));
},
Expand All @@ -1952,7 +1952,7 @@ describe('Store', () => {
}

withErrorsOrWarningsIgnored(
['Warning: Each child in a list should have a unique "key" prop'],
['Each child in a list should have a unique "key" prop'],
() => {
act(() => render(<Example />));
},
Expand Down
12 changes: 11 additions & 1 deletion packages/react-devtools-shell/src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@ ignoreErrors([
'Warning: %s is deprecated in StrictMode.', // findDOMNode
'Warning: ReactDOM.render was removed in React 19',
'Warning: react-test-renderer is deprecated',
// Ignore prefixed and not prefixed since I don't know which
// React versions are being tested by this code.
'Legacy context API',
'Unsafe lifecycle methods',
'%s is deprecated in StrictMode.', // findDOMNode
'ReactDOM.render was removed in React 19',
'react-test-renderer is deprecated',
]);
ignoreWarnings([
'Warning: componentWillReceiveProps has been renamed',
'componentWillReceiveProps has been renamed'
]);
ignoreWarnings(['Warning: componentWillReceiveProps has been renamed']);
ignoreLogs([]);

const unmountFunctions: Array<() => void | boolean> = [];
Expand Down

0 comments on commit 0364e97

Please sign in to comment.