Skip to content

Commit 366de9f

Browse files
committed
wip: kinda working
1 parent a654e36 commit 366de9f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/unit/node/app.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,36 @@ describe("createApp", () => {
6363
// Cleanup
6464
server.close()
6565
})
66+
67+
it("should reject errors", async () => {
68+
const port = 2
69+
const defaultArgs = await setDefaults({
70+
port,
71+
_: [],
72+
})
73+
74+
// This looks funky, but that's because createApp
75+
// returns an array like [app, wsApp, server]
76+
// We only need server which is at index 2
77+
// we do it this way so ESLint is happy that we're
78+
// have no declared variables not being used
79+
async function masterBall() {
80+
const app = await createApp(defaultArgs)
81+
const server = app[2]
82+
83+
const testError = new Error("Test error")
84+
// Emitting error events on servers
85+
// https://stackoverflow.com/a/33872506/3015595
86+
server.emit("error", testError)
87+
// expect(spy).toHaveBeenCalledTimes(1)
88+
// expect(spy).toHaveBeenCalledWith(`http server error: ${testError.message} ${testError.stack}`)
89+
90+
// Cleanup
91+
server.close()
92+
}
93+
94+
expect(() => masterBall()).rejects.toThrow(`listen EACCES: permission denied 127.0.0.1:${port}`)
95+
})
6696
})
6797

6898
describe("ensureAddress", () => {

0 commit comments

Comments
 (0)