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('#RFB (constructor)', function () {
|
||||
let open;
|
||||
let open, attach;
|
||||
beforeEach(function () {
|
||||
open = sinon.spy(Websock.prototype, 'open');
|
||||
attach = sinon.spy(Websock.prototype, 'attach');
|
||||
});
|
||||
afterEach(function () {
|
||||
open.restore();
|
||||
attach.restore();
|
||||
});
|
||||
|
||||
it('should not connect from constructor', function () {
|
||||
|
@ -160,6 +162,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
|||
this.clock.tick();
|
||||
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 () {
|
||||
|
|
|
@ -270,6 +270,27 @@ describe('Websock', function () {
|
|||
// 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 () {
|
||||
beforeEach(function () {
|
||||
sock.open('ws://localhost');
|
||||
|
|
Loading…
Reference in New Issue