Suppress act() warnings in DevTools tests (#23192)
These warnings are not useful for DevTools tests– and sometimes may mask other, important warnings. This commit disables them.
Brian Vaughn committed
Jan 26, 2022 at 15:18 UTC
3d1e7e72783bbd03d5d28c5e9d682da98d6b426e
3 files changed
+54
-21
packages/react-devtools-shared/src/__tests__/editing-test.js
+1
-1
@@ -19,7 +19,7 @@ describe('editing interface', () => {
19
let utils;
20
21
const flushPendingUpdates = () => {
22
- jest.runOnlyPendingTimers();
22
+ utils.act(() => jest.runOnlyPendingTimers());
23
};
24
25
beforeEach(() => {
packages/react-devtools-shared/src/__tests__/inspectedElement-test.js
+37
-16
@@ -71,8 +71,10 @@ describe('InspectedElement', () => {
71
.TreeContextController;
72
73
// 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
+ });
78
});
79
80
errorBoundaryInstance = null;
@@ -299,9 +301,14 @@ describe('InspectedElement', () => {
301
// from props like defaultSelectedElementID and it's easier to reset here than
302
// to read the TreeDispatcherContext and update the selected ID that way.
303
// 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
+ );
312
313
const inspectedElement = await inspectElementAtIndex(index);
314
@@ -460,9 +467,14 @@ describe('InspectedElement', () => {
467
// The backend still thinks the most recently-inspected element is still cached,
468
// so the frontend needs to tell it to resend a full value.
469
// 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
+ );
478
479
const {
480
clearCacheForTests,
@@ -2024,9 +2036,14 @@ describe('InspectedElement', () => {
2036
// from props like defaultSelectedElementID and it's easier to reset here than
2037
// to read the TreeDispatcherContext and update the selected ID that way.
2038
// 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
+ );
2047
2048
// Select/inspect the same element again
2049
inspectedElement = await inspectElementAtIndex(0);
@@ -2743,11 +2760,15 @@ describe('InspectedElement', () => {
2760
0,
2761
): any): number);
2762
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
+ );
2772
return inspectElementAtIndex(index);
2773
};
2774
const toggleError = async forceError => {
packages/react-devtools-shared/src/__tests__/setupTests.js
+16
-4
@@ -66,9 +66,13 @@ env.beforeEach(() => {
66
if (typeof firstArg !== 'string') {
67
return false;
68
}
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;
76
}
77
78
const originalConsoleError = console.error;
@@ -82,7 +86,15 @@ env.beforeEach(() => {
86
throw args[1];
87
} else if (
88
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
+ ))
98
) {
99
// DevTools intentionally wraps updates with acts from both DOM and test-renderer,
100
// since test updates are expected to impact both renderers.