// A timer the popup started and that fires after cleanupPopup() has removed // the page throws "document is not defined", and the throw fails whatever test // the jest worker is running by then, in this file or another // (https://git.eeqj.de/sneak/AutistMask/issues/578). The flash message's // timer is the one that did it. A throw from a timer during a test fails that // test, so each test here passes only if nothing throws. const { bootPopup, cleanupPopup, unversionedValidProfile, } = require("./support/popupBoot"); const FLASH_MS = 10; function wait(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); } afterEach(() => { cleanupPopup(); }); test("a flash message clears while the page is up", async () => { const page = await bootPopup(unversionedValidProfile()); const { showFlash } = require("../src/popup/views/helpers"); showFlash("Copied.", FLASH_MS); expect(page.text("flash-msg")).toBe("Copied."); await wait(FLASH_MS * 5); expect(page.text("flash-msg")).toBe(""); }); test("a flash message's timer does not fire after cleanupPopup()", async () => { await bootPopup(unversionedValidProfile()); const { showFlash } = require("../src/popup/views/helpers"); showFlash("Copied.", FLASH_MS); cleanupPopup(); await wait(FLASH_MS * 5); });