Skip to content

Commit 8716606

Browse files
author
Brian Vaughn
authored
Merge pull request #15 from eps1lon/devtools-inline-warnings-flush-passive-after-delay-test-explicit
Make timing explicit in test
2 parents 0240224 + b7866cf commit 8716606

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,16 +1088,20 @@ describe('Store', () => {
10881088
withErrorsOrWarningsIgnored(['test-only:'], () => {
10891089
act(() => {
10901090
ReactDOM.render(<Example />, container);
1091+
// flush bridge operations
1092+
jest.runOnlyPendingTimers();
1093+
}, false);
1094+
});
10911095

1092-
// Flush commit
1093-
jest.advanceTimersByTime(1);
1096+
expect(store).toMatchInlineSnapshot(`
1097+
[root]
1098+
<Example>
1099+
`);
10941100

1095-
expect(store).toMatchInlineSnapshot(`
1096-
[root]
1097-
<Example>
1098-
`);
1099-
});
1100-
});
1101+
// flush count after delay
1102+
act(() => {
1103+
jest.advanceTimersByTime(1000);
1104+
}, false);
11011105

11021106
// After a delay, passive effects should be committed as well
11031107
expect(store).toMatchInlineSnapshot(`

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import type Store from 'react-devtools-shared/src/devtools/store';
1414
import type {ProfilingDataFrontend} from 'react-devtools-shared/src/devtools/views/Profiler/types';
1515
import type {ElementType} from 'react-devtools-shared/src/types';
1616

17-
export function act(callback: Function): void {
17+
export function act(
18+
callback: Function,
19+
recursivelyFlush: boolean = true,
20+
): void {
1821
const {act: actTestRenderer} = require('react-test-renderer');
1922
const {act: actDOM} = require('react-dom/test-utils');
2023

@@ -24,13 +27,15 @@ export function act(callback: Function): void {
2427
});
2528
});
2629

27-
// Flush Bridge operations
28-
while (jest.getTimerCount() > 0) {
29-
actDOM(() => {
30-
actTestRenderer(() => {
31-
jest.runAllTimers();
30+
if (recursivelyFlush) {
31+
// Flush Bridge operations
32+
while (jest.getTimerCount() > 0) {
33+
actDOM(() => {
34+
actTestRenderer(() => {
35+
jest.runAllTimers();
36+
});
3237
});
33-
});
38+
}
3439
}
3540
}
3641

0 commit comments

Comments
 (0)