Fix stuff happening based on timers not being run correctly in unit tests (#5764)

* Introduce helper for advancing fake time

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Introduce reactive now to kludge around global shared state in library

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Replace all usages of "now" from mobx-utils with our own kludge to get rid of shared global state between unit tests

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Consolidate all usages of advanceTimersByTime to make sure things happening based on timers are run correctly

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Fix incorrect expect in test

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Enable skipped unit test since prerequisites are done

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen authored and GitHub committed 2022-07-01 19:40:34 +03:00
1 parent 3480b517c1
commit 5f57213179
13 files changed
+190 -30

No files matched your search

@@ -10,6 +10,7 @@ import { lensWindowInjectionToken } from "../../main/start-main-application/lens
import exitAppInjectable from "../../main/electron-app/features/exit-app.injectable";
import clusterManagerInjectable from "../../main/cluster-manager.injectable";
import stopServicesAndExitAppInjectable from "../../main/stop-services-and-exit-app.injectable";
import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time";
describe("quitting the app using application menu", () => {
describe("given application has started", () => {
@@ -18,7 +19,7 @@ describe("quitting the app using application menu", () => {
let exitAppMock: jest.Mock;
beforeEach(async () => {
jest.useFakeTimers();
useFakeTime("2015-10-21T07:28:00Z");
applicationBuilder = getApplicationBuilder().beforeApplicationStart(
({ mainDi }) => {
@@ -71,14 +72,14 @@ describe("quitting the app using application menu", () => {
});
it("after insufficient time passes, does not terminate application yet", () => {
jest.advanceTimersByTime(999);
advanceFakeTime(999);
expect(exitAppMock).not.toHaveBeenCalled();
});
describe("after sufficient time passes", () => {
beforeEach(() => {
jest.advanceTimersByTime(1000);
advanceFakeTime(1000);
});
it("terminates application", () => {