Skip to content

Commit 03612c0

Browse files
committed
Fix handle error listener
1 parent 3ba154f commit 03612c0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/infrastructure/Listener.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export class Listener {
107107
this.webSocket.onerror = (err) => {
108108
console.log('WebSocket Error ');
109109
console.log(err);
110+
reject(err);
110111
};
111112
this.webSocket.onmessage = (msg) => {
112113
const message = JSON.parse(msg.data as string);

test/infrastructure/Listener.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,17 @@ describe('Listener', () => {
3131
listener.close();
3232
});
3333
});
34+
35+
describe('onerror', () => {
36+
it('should reject because of wrong server url', async () => {
37+
const listener = new Listener('https://notcorrecturl:0000');
38+
await listener.open()
39+
.then((result) => {
40+
throw new Error('This should not be called when expecting error');
41+
})
42+
.catch((error) => {
43+
expect(error.toString()).to.be.equal("Error: getaddrinfo ENOTFOUND notcorrecturl notcorrecturl:0000");
44+
})
45+
});
46+
});
3447
});

0 commit comments

Comments
 (0)