diff --git a/packages/core/test/overlay/overlayTests.tsx b/packages/core/test/overlay/overlayTests.tsx index f581d8c040..0f864bfe2c 100644 --- a/packages/core/test/overlay/overlayTests.tsx +++ b/packages/core/test/overlay/overlayTests.tsx @@ -200,11 +200,16 @@ describe("", () => { let buttonRef: HTMLElement; const focusBtnAndAssert = () => { buttonRef.focus(); + // nested setTimeouts delay execution until the next frame, not + // just to the end of the current frame. necessary to wait for + // focus to change. setTimeout(() => { - wrapper.update(); - assert.notStrictEqual(buttonRef, document.activeElement); - done(); - }, 10); + setTimeout(() => { + wrapper.update(); + assert.notStrictEqual(buttonRef, document.activeElement); + done(); + }); + }); }; wrapper = mount( @@ -302,12 +307,15 @@ describe("", () => { function assertFocus(selector: string, done: MochaDone) { wrapper.update(); - // small explicit timeout reduces flakiness of these tests, - // which rely on requestAnimationFrame to update focus state. + // the behavior being tested relies on requestAnimationFrame. to + // avoid flakiness, use nested setTimeouts to delay execution until + // the next frame, not just to the end of the current frame. setTimeout(() => { - assert.strictEqual(document.querySelector(selector), document.activeElement); - done(); - }, 10); + setTimeout(() => { + assert.strictEqual(document.querySelector(selector), document.activeElement); + done(); + }); + }); } });