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", () => {
|
describe("getStartableStoppable", () => {
|
||||||
let stopMock: jest.Mock<() => void>;
|
let stopMock: jest.Mock<() => void>;
|
||||||
let startMock: jest.Mock<() => () => void>;
|
let startMock: jest.Mock<() => () => void>;
|
||||||
let actual: { stop: () => void; start: () => void };
|
let actual: { stop: () => void; start: () => void; started: boolean };
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
stopMock = jest.fn();
|
stopMock = jest.fn();
|
||||||
@ -30,6 +30,10 @@ describe("getStartableStoppable", () => {
|
|||||||
}).toThrow("Tried to stop \"some-id\", but it has not started yet.");
|
}).toThrow("Tried to stop \"some-id\", but it has not started yet.");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("is not started", () => {
|
||||||
|
expect(actual.started).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
describe("when started", () => {
|
describe("when started", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
actual.start();
|
actual.start();
|
||||||
@ -39,6 +43,10 @@ describe("getStartableStoppable", () => {
|
|||||||
expect(startMock).toHaveBeenCalled();
|
expect(startMock).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("is started", () => {
|
||||||
|
expect(actual.started).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it("when started again, throws", () => {
|
it("when started again, throws", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
actual.start();
|
actual.start();
|
||||||
@ -58,6 +66,10 @@ describe("getStartableStoppable", () => {
|
|||||||
expect(stopMock).toHaveBeenCalled();
|
expect(stopMock).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("is not started", () => {
|
||||||
|
expect(actual.started).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it("when stopped again, throws", () => {
|
it("when stopped again, throws", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
actual.stop();
|
actual.stop();
|
||||||
@ -75,6 +87,10 @@ describe("getStartableStoppable", () => {
|
|||||||
expect(startMock).toHaveBeenCalled();
|
expect(startMock).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("is started", () => {
|
||||||
|
expect(actual.started).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it("when stopped, stops", () => {
|
it("when stopped, stops", () => {
|
||||||
stopMock.mockClear();
|
stopMock.mockClear();
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,10 @@ export const getStartableStoppable = (
|
|||||||
let started = false;
|
let started = false;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
get started() {
|
||||||
|
return started;
|
||||||
|
},
|
||||||
|
|
||||||
start: () => {
|
start: () => {
|
||||||
if (started) {
|
if (started) {
|
||||||
throw new Error(`Tried to start "${id}", but it has already started.`);
|
throw new Error(`Tried to start "${id}", but it has already started.`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user