Skip to content

Commit cb67837

Browse files
committed
wip: finish tests for handleServerError
1 parent 804f289 commit cb67837

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`handleServerError should log an error if resolved is true 1`] = `"Cannot read property 'handle' of undefined"`;

test/unit/node/app.test.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { logger } from "@coder/logger"
22
import * as http from "http"
3-
import { createApp, ensureAddress } from "../../../src/node/app"
3+
import { createApp, ensureAddress, handleServerError } from "../../../src/node/app"
44
import { setDefaults } from "../../../src/node/cli"
55
import { getAvailablePort } from "../../utils/helpers"
66

@@ -122,5 +122,40 @@ describe("ensureAddress", () => {
122122
})
123123
})
124124

125-
// TODO@jsjoeio
126-
// write tests for handleServerError
125+
describe("handleServerError", () => {
126+
let spy: jest.SpyInstance
127+
128+
beforeEach(() => {
129+
spy = jest.spyOn(logger, "error")
130+
})
131+
132+
afterEach(() => {
133+
jest.clearAllMocks()
134+
})
135+
136+
afterAll(() => {
137+
jest.restoreAllMocks()
138+
})
139+
140+
it("should call reject if resolved is false", async () => {
141+
const resolved = false
142+
const reject = jest.fn((err: Error) => undefined)
143+
const error = new Error("handleServerError Error")
144+
145+
handleServerError(resolved, error, reject)
146+
147+
expect(reject).toHaveBeenCalledTimes(1)
148+
expect(reject).toHaveBeenCalledWith(error)
149+
})
150+
151+
it("should log an error if resolved is true", async () => {
152+
const resolved = true
153+
const reject = jest.fn((err: Error) => undefined)
154+
const error = new Error("handleServerError Error")
155+
156+
handleServerError(resolved, error, reject)
157+
158+
expect(spy).toHaveBeenCalledTimes(1)
159+
expect(spy).toThrowErrorMatchingSnapshot()
160+
})
161+
})

0 commit comments

Comments
 (0)