diff --git a/src/common/utils/get-startable-stoppable.test.ts b/src/common/utils/get-startable-stoppable.test.ts index 8ed213c265..0e5410f664 100644 --- a/src/common/utils/get-startable-stoppable.test.ts +++ b/src/common/utils/get-startable-stoppable.test.ts @@ -39,6 +39,12 @@ describe("getStartableStoppable", () => { expect(startMock).toHaveBeenCalled(); }); + it("when started again, throws", () => { + expect(() => { + actual.start(); + }).toThrow("Tried to start something that has already started."); + }); + it("does not stop yet", () => { expect(stopMock).not.toHaveBeenCalled(); }); @@ -58,10 +64,24 @@ describe("getStartableStoppable", () => { }).toThrow("Tried to stop something that has already stopped."); }); - it("when started again, throws for restart being YAGNI with logical blind spots", () => { - expect(() => { + describe("when started again", () => { + beforeEach(() => { + startMock.mockClear(); + actual.start(); - }).toThrow("Tried to restart something that has stopped."); + }); + + it("starts", () => { + expect(startMock).toHaveBeenCalled(); + }); + + it("when stopped, stops", () => { + stopMock.mockClear(); + + actual.stop(); + + expect(stopMock).toHaveBeenCalled(); + }); }); }); }); diff --git a/src/common/utils/get-startable-stoppable.ts b/src/common/utils/get-startable-stoppable.ts index a28897fb27..11dc8efa34 100644 --- a/src/common/utils/get-startable-stoppable.ts +++ b/src/common/utils/get-startable-stoppable.ts @@ -12,22 +12,26 @@ export const getStartableStoppable = ( return { start: () => { if (started) { - throw new Error("Tried to restart something that has stopped."); + throw new Error("Tried to start something that has already started."); } + stopped = false; + dispose = startAndGetStopCallback(); started = true; }, stop: () => { + if (stopped) { + throw new Error("Tried to stop something that has already stopped."); + } + if (!started) { throw new Error("Tried to stop something that has not started yet."); } - if (stopped) { - throw new Error("Tried to stop something that has already stopped."); - } + started = false; dispose();