Commit b084d0a4 authored by Solly Ross's avatar Solly Ross

Actually throw errors in tests

parent f00193e0
......@@ -167,7 +167,7 @@ var RFB;
try {
this._display = new Display({target: this._target});
} catch (exc) {
Util.Error("Display exception: " + exc);
Util.Error("Display exception:", exc);
throw exc;
}
......
......@@ -217,7 +217,7 @@ Util.init_logging = function (level) {
case 'warn':
Util.Warn = function (msg) { console.warn(msg); };
case 'error':
Util.Error = function (msg) { console.error(msg); };
Util.Error = function (msg, err) { console.error(msg, err); };
case 'none':
break;
default:
......
......@@ -375,31 +375,8 @@ function Websock() {
Util.Debug("Ignoring empty message");
}
} catch (exc) {
var exception_str = "";
if (exc.name) {
exception_str += "\n name: " + exc.name + "\n";
exception_str += " message: " + exc.message + "\n";
}
if (typeof exc.description !== 'undefined') {
exception_str += " description: " + exc.description + "\n";
}
if (typeof exc.stack !== 'undefined') {
exception_str += exc.stack;
}
if (exception_str.length > 0) {
Util.Error("recv_message, caught exception: " + exception_str);
} else {
Util.Error("recv_message, caught exception: " + exc);
}
if (typeof exc.name !== 'undefined') {
this._eventHandlers.error(exc.name + ": " + exc.message);
} else {
this._eventHandlers.error(exc);
}
Util.Error("recv_message, caught exception:", exc);
this._eventHandlers.error(exc)
}
}
};
......
......@@ -32,6 +32,12 @@ describe('Remote Frame Buffer Protocol Client', function() {
this._rQ = rQ;
};
// Actually throw errors
if (Util.__Error === undefined) { Util.__Error = Util.Error; }
Util.Error = function (msg, err) {
if (err) { throw err; }
Util.__Error(msg, err);
};
});
after(function () {
......
......@@ -7,6 +7,19 @@ var expect = chai.expect;
describe('Websock', function() {
"use strict";
function throwUtilError() {
if (Util.__Error === undefined) { Util.__Error = Util.Error; }
Util.Error = function (msg, err) {
if (err) { throw err; }
Util.__Error(msg, err);
};
}
before(function () {
// Actually throw errors
throwUtilError();
});
describe('Queue methods', function () {
var sock;
var RQ_TEMPLATE = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
......@@ -405,12 +418,14 @@ describe('Websock', function() {
});
it('should call the error event handler on an exception', function () {
Util.Error = Util.__Error;
sock._eventHandlers.error = sinon.spy();
sock._eventHandlers.message = sinon.stub().throws();
var msg = { data: new Uint8Array([1, 2, 3]).buffer };
sock._mode = 'binary';
sock._recv_message(msg);
expect(sock._eventHandlers.error).to.have.been.calledOnce;
throwUtilError();
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment