Skip to content

Commit e642ad6

Browse files
author
Peter Sorowka
committed
Added unit tests for receiver error emission
1 parent f804cdb commit e642ad6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/WebSocket.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,40 @@ describe('WebSocket', function() {
4949
done();
5050
}
5151
});
52+
53+
it('should emit an error object when the receiver throws an error string', function(done) {
54+
55+
var wss = new WebSocketServer({port: ++port}, function() {
56+
57+
var ws = new WebSocket('ws://localhost:' + port);
58+
59+
ws.on('open', function () {
60+
ws._receiver.error('This is an error string', 1002);
61+
});
62+
63+
ws.on('error', function (error) {
64+
error.should.be.an.instanceof(Error);
65+
done();
66+
});
67+
});
68+
});
69+
70+
it('should emit an error object when the receiver throws an error object', function(done) {
71+
72+
var wss = new WebSocketServer({port: ++port}, function() {
73+
74+
var ws = new WebSocket('ws://localhost:' + port);
75+
76+
ws.on('open', function () {
77+
ws._receiver.error(new Error('This is an error object'), 1002);
78+
});
79+
80+
ws.on('error', function (error) {
81+
error.should.be.an.instanceof(Error);
82+
done();
83+
});
84+
});
85+
});
5286
});
5387

5488
describe('options', function() {

0 commit comments

Comments
 (0)