Skip to content

Commit 3d1e7e7

Browse files
author
Brian Vaughn
authored
Suppress act() warnings in DevTools tests (facebook#23192)
These warnings are not useful for DevTools tests– and sometimes may mask other, important warnings. This commit disables them.
1 parent 934f722 commit 3d1e7e7

File tree

3 files changed

+54
-21
lines changed

3 files changed

+54
-21
lines changed

packages/react-devtools-shared/src/__tests__/editing-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('editing interface', () => {
1919
let utils;
2020

2121
const flushPendingUpdates = () => {
22-
jest.runOnlyPendingTimers();
22+
utils.act(() => jest.runOnlyPendingTimers());
2323
};
2424

2525
beforeEach(() => {

packages/react-devtools-shared/src/__tests__/inspectedElement-test.js

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ describe('InspectedElement', () => {
7171
.TreeContextController;
7272

7373
// Used by inspectElementAtIndex() helper function
74-
testRendererInstance = TestRenderer.create(null, {
75-
unstable_isConcurrent: true,
74+
utils.act(() => {
75+
testRendererInstance = TestRenderer.create(null, {
76+
unstable_isConcurrent: true,
77+
});
7678
});
7779

7880
errorBoundaryInstance = null;
@@ -299,9 +301,14 @@ describe('InspectedElement', () => {
299301
// from props like defaultSelectedElementID and it's easier to reset here than
300302
// to read the TreeDispatcherContext and update the selected ID that way.
301303
// We're testing the inspected values here, not the context wiring, so that's ok.
302-
testRendererInstance = TestRenderer.create(null, {
303-
unstable_isConcurrent: true,
304-
});
304+
utils.withErrorsOrWarningsIgnored(
305+
['An update to %s inside a test was not wrapped in act'],
306+
() => {
307+
testRendererInstance = TestRenderer.create(null, {
308+
unstable_isConcurrent: true,
309+
});
310+
},
311+
);
305312

306313
const inspectedElement = await inspectElementAtIndex(index);
307314

@@ -460,9 +467,14 @@ describe('InspectedElement', () => {
460467
// The backend still thinks the most recently-inspected element is still cached,
461468
// so the frontend needs to tell it to resend a full value.
462469
// We can verify this by asserting that the component is re-rendered again.
463-
testRendererInstance = TestRenderer.create(null, {
464-
unstable_isConcurrent: true,
465-
});
470+
utils.withErrorsOrWarningsIgnored(
471+
['An update to %s inside a test was not wrapped in act'],
472+
() => {
473+
testRendererInstance = TestRenderer.create(null, {
474+
unstable_isConcurrent: true,
475+
});
476+
},
477+
);
466478

467479
const {
468480
clearCacheForTests,
@@ -2024,9 +2036,14 @@ describe('InspectedElement', () => {
20242036
// from props like defaultSelectedElementID and it's easier to reset here than
20252037
// to read the TreeDispatcherContext and update the selected ID that way.
20262038
// We're testing the inspected values here, not the context wiring, so that's ok.
2027-
testRendererInstance = TestRenderer.create(null, {
2028-
unstable_isConcurrent: true,
2029-
});
2039+
utils.withErrorsOrWarningsIgnored(
2040+
['An update to %s inside a test was not wrapped in act'],
2041+
() => {
2042+
testRendererInstance = TestRenderer.create(null, {
2043+
unstable_isConcurrent: true,
2044+
});
2045+
},
2046+
);
20302047

20312048
// Select/inspect the same element again
20322049
inspectedElement = await inspectElementAtIndex(0);
@@ -2743,11 +2760,15 @@ describe('InspectedElement', () => {
27432760
0,
27442761
): any): number);
27452762
const inspect = index => {
2746-
// HACK: Recreate TestRenderer instance so we can inspect different
2747-
// elements
2748-
testRendererInstance = TestRenderer.create(null, {
2749-
unstable_isConcurrent: true,
2750-
});
2763+
// HACK: Recreate TestRenderer instance so we can inspect different elements
2764+
utils.withErrorsOrWarningsIgnored(
2765+
['An update to %s inside a test was not wrapped in act'],
2766+
() => {
2767+
testRendererInstance = TestRenderer.create(null, {
2768+
unstable_isConcurrent: true,
2769+
});
2770+
},
2771+
);
27512772
return inspectElementAtIndex(index);
27522773
};
27532774
const toggleError = async forceError => {

packages/react-devtools-shared/src/__tests__/setupTests.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@ env.beforeEach(() => {
6666
if (typeof firstArg !== 'string') {
6767
return false;
6868
}
69-
return global._ignoredErrorOrWarningMessages.some(errorOrWarningMessage => {
70-
return firstArg.indexOf(errorOrWarningMessage) !== -1;
71-
});
69+
const shouldFilter = global._ignoredErrorOrWarningMessages.some(
70+
errorOrWarningMessage => {
71+
return firstArg.indexOf(errorOrWarningMessage) !== -1;
72+
},
73+
);
74+
75+
return shouldFilter;
7276
}
7377

7478
const originalConsoleError = console.error;
@@ -82,7 +86,15 @@ env.beforeEach(() => {
8286
throw args[1];
8387
} else if (
8488
typeof firstArg === 'string' &&
85-
firstArg.startsWith("Warning: It looks like you're using the wrong act()")
89+
(firstArg.startsWith(
90+
"Warning: It looks like you're using the wrong act()",
91+
) ||
92+
firstArg.startsWith(
93+
'Warning: The current testing environment is not configured to support act',
94+
) ||
95+
firstArg.startsWith(
96+
'Warning: You seem to have overlapping act() calls',
97+
))
8698
) {
8799
// DevTools intentionally wraps updates with acts from both DOM and test-renderer,
88100
// since test updates are expected to impact both renderers.

0 commit comments

Comments
 (0)