Skip to content

Commit

Permalink
Properly flush updates
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jun 26, 2021
1 parent 39c3fa2 commit c879124
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions test/utils/userEvent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react';
import { click, mouseDown, mouseUp } from './fireDiscreteEvent';
import { act, fireEvent } from './createClientRender';

Expand All @@ -7,9 +8,16 @@ export function touch(target: Element): void {
}

export function mousePress(target: Element): void {
mouseDown(target);
mouseUp(target);
click(target);
// Flush scheduled effects
act(() => {});
if (typeof (React as any).unstable_act === 'function') {
(React as any).unstable_act(() => {
mouseDown(target);
mouseUp(target);
click(target);
});
} else {
mouseDown(target);
mouseUp(target);
click(target);
act(() => {});
}
}

0 comments on commit c879124

Please sign in to comment.