Skip to content

Commit

Permalink
[test] Ignore ReactDOM.render deprecation warning (#26683)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Jun 11, 2021
1 parent 23a4ce6 commit 07f638f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 2 additions & 3 deletions test/utils/createServerRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ export default function createServerRender(options = {}) {
const { expectUseLayoutEffectWarning = false } = options;

beforeEach(() => {
const originalConsoleError = console.error;
stub(console, 'error').callsFake((message, ...args) => {
const isUseLayoutEffectWarning = /Warning: useLayoutEffect does nothing on the server/.test(
message,
);

if (!expectUseLayoutEffectWarning || !isUseLayoutEffectWarning) {
// callThrough
// eslint-disable-next-line no-console
console.info(message, ...args);
throw new Error(message, ...args);
originalConsoleError(message, ...args);
}
});
});
Expand Down
5 changes: 5 additions & 0 deletions test/utils/initMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ chai.use((chaiAPI, utils) => {
const originalMethod = console[methodName];

const consoleMatcher = (format: string, ...args: readonly unknown[]) => {
// Ignore ReactDOM.render deprecation warning
// TODO: Remove once we no longer use legacy roots.
if (format.indexOf('Use createRoot instead.') !== -1) {
return;
}
const actualMessage = formatUtil(format, ...args);
const expectedMessage = remainingMessages.shift();

Expand Down
6 changes: 6 additions & 0 deletions test/utils/mochaHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ function createUnexpectedConsoleMessagesHooks(Mocha, methodName, expectedMatcher
}
}

// Ignore ReactDOM.render deprecation warning
// TODO: Remove once we no longer use legacy roots.
if (message.indexOf('Use createRoot instead.') !== -1) {
return;
}

unexpectedCalls.push([
// first line includes the (empty) error message
// i.e. Remove the `Error:` line
Expand Down

0 comments on commit 07f638f

Please sign in to comment.