mirror of https://git.tuxpa.in/a/code-server.git
feat: add test for catching errors in Emitter
This commit is contained in:
parent
b232dcbd4a
commit
80a180079e
|
@ -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")
|
||||
|
|
|
@ -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..
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue