Skip to content

Commit dfae8df

Browse files
author
Deepak Kumar
committed
Add unit tests for connecting with webSocketFactory and pre-opened WebSocket
1 parent a3482de commit dfae8df

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

spec/unit/connection.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,38 @@ describe('Stomp Connection', function () {
3131
client.activate();
3232
});
3333

34+
it('Connect with a webSocketFactory', function (done) {
35+
client = stompClient();
36+
37+
client.brokerURL = undefined;
38+
client.webSocketFactory = () => new WebSocket(TEST.url);
39+
40+
client.onConnect = function () {
41+
done();
42+
};
43+
44+
client.activate();
45+
});
46+
47+
it('Connect with a websocket that is already open', function (done) {
48+
client = stompClient();
49+
50+
client.brokerURL = undefined;
51+
const socket = new WebSocket(TEST.url);
52+
53+
client.webSocketFactory = () => socket;
54+
55+
client.onConnect = function () {
56+
done();
57+
};
58+
59+
socket.onopen = () => {
60+
expect(socket.readyState).toEqual(WebSocket.OPEN);
61+
62+
client.activate();
63+
}
64+
})
65+
3466
it('Should not connect with invalid credentials', function (done) {
3567
client = stompClient();
3668
client.configure({

0 commit comments

Comments
 (0)