-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathParseWebSocket.spec.js
42 lines (36 loc) · 1.02 KB
/
ParseWebSocket.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const ParseWebSocket = require('../lib/LiveQuery/ParseWebSocketServer').ParseWebSocket;
describe('ParseWebSocket', function () {
it('can be initialized', function () {
const ws = {};
const parseWebSocket = new ParseWebSocket(ws);
expect(parseWebSocket.ws).toBe(ws);
});
it('can handle disconnect event', function (done) {
const ws = {
onclose: () => {},
};
const parseWebSocket = new ParseWebSocket(ws);
parseWebSocket.on('disconnect', () => {
done();
});
ws.onclose();
});
it('can handle message event', function (done) {
const ws = {
onmessage: () => {},
};
const parseWebSocket = new ParseWebSocket(ws);
parseWebSocket.on('message', () => {
done();
});
ws.onmessage();
});
it('can send a message', function () {
const ws = {
send: jasmine.createSpy('send'),
};
const parseWebSocket = new ParseWebSocket(ws);
parseWebSocket.send('message');
expect(parseWebSocket.ws.send).toHaveBeenCalledWith('message');
});
});