1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/common/utils/get-startable-stoppable.test.ts
Sebastian Malton b498f12186
Refactor runnables (#6528)
* Convert runManyFor to use composite

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Convert runManySyncFor to use composite and to enfore sync-ness

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Remove dead code

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Convert getStartableStoppable to be always sync as it is never used in an async fashion

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Convert all sync runnables to comply with new checks for sync-ness

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-11-07 19:04:56 +02:00

63 lines
1.6 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { StartableStoppable } from "./get-startable-stoppable";
import { getStartableStoppable } from "./get-startable-stoppable";
describe("getStartableStoppable", () => {
let stopMock: jest.MockedFunction<() => void>;
let startMock: jest.MockedFunction<() => () => void>;
let actual: StartableStoppable;
beforeEach(() => {
stopMock = jest.fn();
startMock = jest.fn().mockImplementation(() => stopMock);
actual = getStartableStoppable("some-id", startMock);
});
it("does not start yet", () => {
expect(startMock).not.toHaveBeenCalled();
});
it("does not stop yet", () => {
expect(stopMock).not.toHaveBeenCalled();
});
it("when stopping before ever starting, throws", () => {
expect(() => actual.stop()).toThrow("Tried to stop \"some-id\", but it is already stopped.");
});
it("is not started", () => {
expect(actual.started).toBe(false);
});
describe("when started", () => {
beforeEach(() => {
actual.start();
});
it("calls start function", () => {
expect(startMock).toHaveBeenCalled();
});
it("is started", () => {
expect(actual.started).toBe(true);
});
describe("when stopped", () => {
beforeEach(() => {
actual.stop();
});
it("calls stop function", () => {
expect(stopMock).toBeCalled();
});
it("is stopped", () => {
expect(actual.started).toBe(false);
});
});
});
});