Skip to content

Commit 95d4506

Browse files
Fix flaky tests in Popover, Overlay2, and Table components (#7596)
Co-authored-by: Gregory Douglas <[email protected]>
1 parent 40c43b9 commit 95d4506

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

packages/core/test/overlay2/overlay2Tests.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
Portal,
3232
Utils,
3333
} from "../../src";
34-
import { findInPortal, sleep } from "../utils";
34+
import { findInPortal } from "../utils";
3535

3636
import "./overlay2-test-debugging.scss";
3737

@@ -723,7 +723,13 @@ describe("<Overlay2>", () => {
723723
assert.isTrue(onOpening.calledOnce, "onOpening");
724724
assert.isFalse(onOpened.calledOnce, "onOpened not called yet");
725725

726-
await sleep(10);
726+
// Wait for transition to complete and onOpened to be called
727+
await waitFor(
728+
() => {
729+
assert.isTrue(onOpened.calledOnce, "onOpened");
730+
},
731+
{ timeout: 100 },
732+
);
727733

728734
// on*ed called after transition completes
729735
assert.isTrue(onOpened.calledOnce, "onOpened");
@@ -733,9 +739,15 @@ describe("<Overlay2>", () => {
733739
assert.isTrue(onClosing.calledOnce, "onClosing");
734740
assert.isFalse(onClosed.calledOnce, "onClosed not called yet");
735741

736-
await sleep(10);
742+
// Wait for transition to complete and onClosed to be called
743+
await waitFor(
744+
() => {
745+
assert.isTrue(onClosed.calledOnce, "onClosed");
746+
},
747+
{ timeout: 100 },
748+
);
737749

738-
assert.isTrue(onClosed.calledOnce, "onOpened");
750+
assert.isTrue(onClosed.calledOnce, "onClosed");
739751
});
740752

741753
let index = 0;

packages/core/test/popover/popoverTests.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ describe("<Popover>", () => {
345345
);
346346
const targetButton = screen.getByRole("button", { name: "target" });
347347

348-
userEvent.click(targetButton);
348+
await userEvent.click(targetButton);
349349

350350
const overlay = container.querySelector(`.${Classes.OVERLAY}`);
351351

@@ -357,7 +357,7 @@ describe("<Popover>", () => {
357357

358358
const closeButton = screen.getByRole("button", { name: "close" });
359359

360-
userEvent.click(closeButton);
360+
await userEvent.click(closeButton);
361361

362362
await waitFor(() => {
363363
expect(hasClass(overlay!, Classes.OVERLAY_OPEN)).to.be.false;

packages/table/test/quadrants/tableQuadrantStackTests.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { expect } from "chai";
1818
import { mount } from "enzyme";
19+
import { act } from "react";
1920
import * as TestUtils from "react-dom/test-utils";
2021
import sinon from "sinon";
2122

@@ -577,7 +578,9 @@ describe("TableQuadrantStack", () => {
577578
});
578579

579580
it("invokes onScroll on TOP quadrant wheel", () => {
580-
TestUtils.Simulate.wheel(topScrollContainer);
581+
act(() => {
582+
TestUtils.Simulate.wheel(topScrollContainer);
583+
});
581584
expect(onScroll.calledOnce).to.be.true;
582585
});
583586

0 commit comments

Comments
 (0)