mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make it possible to not stop something that was never started
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
d6a0880df0
commit
ec279d4f5c
@ -7,7 +7,7 @@ import { getStartableStoppable } from "./get-startable-stoppable";
|
||||
describe("getStartableStoppable", () => {
|
||||
let stopMock: jest.Mock<() => void>;
|
||||
let startMock: jest.Mock<() => () => void>;
|
||||
let actual: { stop: () => void; start: () => void };
|
||||
let actual: { stop: () => void; start: () => void; started: boolean };
|
||||
|
||||
beforeEach(() => {
|
||||
stopMock = jest.fn();
|
||||
@ -30,6 +30,10 @@ describe("getStartableStoppable", () => {
|
||||
}).toThrow("Tried to stop \"some-id\", but it has not started yet.");
|
||||
});
|
||||
|
||||
it("is not started", () => {
|
||||
expect(actual.started).toBe(false);
|
||||
});
|
||||
|
||||
describe("when started", () => {
|
||||
beforeEach(() => {
|
||||
actual.start();
|
||||
@ -39,6 +43,10 @@ describe("getStartableStoppable", () => {
|
||||
expect(startMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("is started", () => {
|
||||
expect(actual.started).toBe(true);
|
||||
});
|
||||
|
||||
it("when started again, throws", () => {
|
||||
expect(() => {
|
||||
actual.start();
|
||||
@ -58,6 +66,10 @@ describe("getStartableStoppable", () => {
|
||||
expect(stopMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("is not started", () => {
|
||||
expect(actual.started).toBe(false);
|
||||
});
|
||||
|
||||
it("when stopped again, throws", () => {
|
||||
expect(() => {
|
||||
actual.stop();
|
||||
@ -75,6 +87,10 @@ describe("getStartableStoppable", () => {
|
||||
expect(startMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("is started", () => {
|
||||
expect(actual.started).toBe(true);
|
||||
});
|
||||
|
||||
it("when stopped, stops", () => {
|
||||
stopMock.mockClear();
|
||||
|
||||
|
||||
@ -11,6 +11,10 @@ export const getStartableStoppable = (
|
||||
let started = false;
|
||||
|
||||
return {
|
||||
get started() {
|
||||
return started;
|
||||
},
|
||||
|
||||
start: () => {
|
||||
if (started) {
|
||||
throw new Error(`Tried to start "${id}", but it has already started.`);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user