From d1f5f1cdef9ea6c81f176cdce199b2e7b8e2b0ee Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Fri, 17 Jun 2022 10:25:01 +0300 Subject: [PATCH] Fix flaky unit test (#5661) Signed-off-by: Janne Savolainen --- ...ning-application-window-using-tray.test.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/behaviours/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts b/src/behaviours/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts index 7b7765b988..4b5b6ff338 100644 --- a/src/behaviours/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts +++ b/src/behaviours/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts @@ -12,7 +12,6 @@ import type { AsyncFnMock } from "@async-fn/jest"; import asyncFn from "@async-fn/jest"; import type { ElectronWindow, LensWindowConfiguration } from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable"; import type { DiContainer } from "@ogre-tools/injectable"; -import { flushPromises } from "../../common/test-utils/flush-promises"; import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable"; describe("opening application window using tray", () => { @@ -24,17 +23,28 @@ describe("opening application window using tray", () => { let callForApplicationWindowHtmlMock: AsyncFnMock<() => void>; beforeEach(async () => { + callForSplashWindowHtmlMock = asyncFn(); + callForApplicationWindowHtmlMock = asyncFn(); + applicationBuilder = getApplicationBuilder().beforeApplicationStart( ({ mainDi }) => { mainDi.override(lensResourcesDirInjectable, () => "some-lens-resources-directory"); + const loadFileMock = jest + .fn(callForSplashWindowHtmlMock) + .mockImplementationOnce(() => Promise.resolve()); + + const loadUrlMock = jest + .fn(callForApplicationWindowHtmlMock) + .mockImplementationOnce(() => Promise.resolve()); + createElectronWindowMock = jest.fn((configuration: LensWindowConfiguration) => ({ splash: { send: () => {}, close: () => {}, show: () => {}, - loadFile: callForSplashWindowHtmlMock, + loadFile: loadFileMock, loadUrl: () => { throw new Error("Should never come here"); }, }, @@ -43,7 +53,7 @@ describe("opening application window using tray", () => { close: () => {}, show: () => {}, loadFile: () => { throw new Error("Should never come here"); }, - loadUrl: callForApplicationWindowHtmlMock, + loadUrl: loadUrlMock, }, }[configuration.id] as ElectronWindow)); @@ -54,20 +64,10 @@ describe("opening application window using tray", () => { ); expectWindowsToBeOpen = expectWindowsToBeOpenFor(mainDi); - - callForSplashWindowHtmlMock = asyncFn(); - callForApplicationWindowHtmlMock = asyncFn(); }, ); - const renderPromise = applicationBuilder.render(); - - await flushPromises(); - - await callForSplashWindowHtmlMock.resolve(); - await callForApplicationWindowHtmlMock.resolve(); - - await renderPromise; + await applicationBuilder.render(); }); it("only an application window is open", () => {