diff --git a/src/common/utils/get-startable-stoppable.test.ts b/src/common/utils/get-startable-stoppable.test.ts index 43c95921a5..88279744af 100644 --- a/src/common/utils/get-startable-stoppable.test.ts +++ b/src/common/utils/get-startable-stoppable.test.ts @@ -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(); diff --git a/src/common/utils/get-startable-stoppable.ts b/src/common/utils/get-startable-stoppable.ts index 7b2f0e1fd7..094166de24 100644 --- a/src/common/utils/get-startable-stoppable.ts +++ b/src/common/utils/get-startable-stoppable.ts @@ -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.`);