Add unit tests for passing WebSocket objects
This commit is contained in:
parent
f0e4908dec
commit
ae3c01f782
|
@ -141,12 +141,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
|
|
||||||
describe('Connecting/Disconnecting', function () {
|
describe('Connecting/Disconnecting', function () {
|
||||||
describe('#RFB (constructor)', function () {
|
describe('#RFB (constructor)', function () {
|
||||||
let open;
|
let open, attach;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
open = sinon.spy(Websock.prototype, 'open');
|
open = sinon.spy(Websock.prototype, 'open');
|
||||||
|
attach = sinon.spy(Websock.prototype, 'attach');
|
||||||
});
|
});
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
open.restore();
|
open.restore();
|
||||||
|
attach.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not connect from constructor', function () {
|
it('should not connect from constructor', function () {
|
||||||
|
@ -160,6 +162,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
this.clock.tick();
|
this.clock.tick();
|
||||||
expect(open).to.have.been.calledOnceWithExactly('ws://HOST:8675/PATH', []);
|
expect(open).to.have.been.calledOnceWithExactly('ws://HOST:8675/PATH', []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle WebSocket/RTCDataChannel objects', function () {
|
||||||
|
let sock = new FakeWebSocket('ws://HOST:8675/PATH', []);
|
||||||
|
new RFB(document.createElement('div'), sock);
|
||||||
|
this.clock.tick();
|
||||||
|
expect(open).to.not.have.been.called;
|
||||||
|
expect(attach).to.have.been.calledOnceWithExactly(sock);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#disconnect', function () {
|
describe('#disconnect', function () {
|
||||||
|
|
|
@ -270,6 +270,27 @@ describe('Websock', function () {
|
||||||
// it('should initialize the event handlers')?
|
// it('should initialize the event handlers')?
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('attaching', function () {
|
||||||
|
it('should attach to an existing open websocket', function () {
|
||||||
|
let ws = new FakeWebSocket('ws://localhost:8675');
|
||||||
|
ws._open();
|
||||||
|
let callback = sinon.spy();
|
||||||
|
sock.on('open', callback);
|
||||||
|
sock.attach(ws);
|
||||||
|
expect(WebSocket).to.not.have.been.called;
|
||||||
|
expect(callback).to.have.been.calledOnce;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should attach to an existing connecting websocket', function () {
|
||||||
|
let ws = new FakeWebSocket('ws://localhost:8675');
|
||||||
|
let callback = sinon.spy();
|
||||||
|
sock.on('open', callback);
|
||||||
|
sock.attach(ws);
|
||||||
|
expect(WebSocket).to.not.have.been.called;
|
||||||
|
expect(callback).to.not.have.been.called;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('closing', function () {
|
describe('closing', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sock.open('ws://localhost');
|
sock.open('ws://localhost');
|
||||||
|
|
Loading…
Reference in New Issue