From b48c6b731b6477ed4c579fc23f4da2b7329b82d8 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Thu, 23 Jan 2020 11:18:22 -0500 Subject: [PATCH] add overlay unit test FLUP from #3936 --- packages/core/test/overlay/overlayTests.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/core/test/overlay/overlayTests.tsx b/packages/core/test/overlay/overlayTests.tsx index c7008991dc..033abf3aad 100644 --- a/packages/core/test/overlay/overlayTests.tsx +++ b/packages/core/test/overlay/overlayTests.tsx @@ -368,6 +368,26 @@ describe("", () => { assertFocus("button", done); }); + it("does not crash while trying to return focus to overlay if user clicks outside the document", () => { + mountWrapper( + + {createOverlayContents()} + , + ); + + // this is a fairly custom / nonstandard event dispatch, trying to simulate what happens in some browsers when a user clicks + // on the browser toolbar (outside the document), but a focus event is still dispatched to document + // see https://github.com/palantir/blueprint/issues/3928 + const event = new FocusEvent("focus"); + Object.defineProperty(event, "target", { value: window }); + + try { + document.dispatchEvent(event); + } catch (e) { + assert.fail("threw uncaught error"); + } + }); + function assertFocus(selector: string | (() => void), done: MochaDone) { // the behavior being tested relies on requestAnimationFrame. // setTimeout for a few frames later to let things settle (to reduce flakes).