diff --git a/test/emitter.test.ts b/test/emitter.test.ts index 8ff5106a4..001b13e0d 100644 --- a/test/emitter.test.ts +++ b/test/emitter.test.ts @@ -1,9 +1,10 @@ // Note: we need to import logger from the root // because this is the logger used in logError in ../src/common/util import { logger } from "../node_modules/@coder/logger" + import { Emitter } from "../src/common/emitter" -describe("Emitter", () => { +describe("emitter", () => { let spy: jest.SpyInstance beforeEach(() => { @@ -59,6 +60,25 @@ describe("Emitter", () => { emitter.dispose() }) + it("should log an error if something goes wrong", async () => { + const HELLO_WORLD = "HELLO_WORLD" + const mockCallback = jest.fn(() => "Mock function called") + const message = "You don't have access to that folder." + + const emitter = new Emitter<{ event: string; callback: () => void }>() + + const onHelloWorld = ({ event, callback }: { event: string; callback: () => void }): void => { + if (event === HELLO_WORLD) { + callback() + throw new Error(message) + } + } + + emitter.event(onHelloWorld) + + await emitter.emit({ event: HELLO_WORLD, callback: mockCallback }) + }) + it("should log an error if something goes wrong", async () => { const HELLO_WORLD = "HELLO_WORLD" const mockCallback = jest.fn(() => "Mock function called") diff --git a/test/serviceWorker.test.ts b/test/serviceWorker.test.ts new file mode 100644 index 000000000..32e6effd5 --- /dev/null +++ b/test/serviceWorker.test.ts @@ -0,0 +1,9 @@ +describe("serviceWorker", () => { + it("should add the proper eventListeners", () => { + // make sure install, active and fetch were added as event listeners + }) + + it("should call the proper callbacks", () => { + // somehow test Line 8 with the events waitUntil.. + }) +}) \ No newline at end of file