Skip to content

Make timing explicit in test #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/react-devtools-shared/src/__tests__/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,16 +1088,20 @@ describe('Store', () => {
withErrorsOrWarningsIgnored(['test-only:'], () => {
act(() => {
ReactDOM.render(<Example />, container);
// flush bridge operations
jest.runOnlyPendingTimers();
}, false);
});

// Flush commit
jest.advanceTimersByTime(1);
expect(store).toMatchInlineSnapshot(`
[root]
<Example>
`);

expect(store).toMatchInlineSnapshot(`
[root]
<Example>
`);
});
});
// flush count after delay
act(() => {
jest.advanceTimersByTime(1000);
}, false);

// After a delay, passive effects should be committed as well
expect(store).toMatchInlineSnapshot(`
Expand Down
19 changes: 12 additions & 7 deletions packages/react-devtools-shared/src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import type Store from 'react-devtools-shared/src/devtools/store';
import type {ProfilingDataFrontend} from 'react-devtools-shared/src/devtools/views/Profiler/types';
import type {ElementType} from 'react-devtools-shared/src/types';

export function act(callback: Function): void {
export function act(
callback: Function,
recursivelyFlush: boolean = true,
): void {
const {act: actTestRenderer} = require('react-test-renderer');
const {act: actDOM} = require('react-dom/test-utils');

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

// Flush Bridge operations
while (jest.getTimerCount() > 0) {
actDOM(() => {
actTestRenderer(() => {
jest.runAllTimers();
if (recursivelyFlush) {
// Flush Bridge operations
while (jest.getTimerCount() > 0) {
actDOM(() => {
actTestRenderer(() => {
jest.runAllTimers();
});
});
});
}
}
}

Expand Down