Skip to content

Commit

Permalink
toThrowDeveloperError didn't work at all.
Browse files Browse the repository at this point in the history
Also correct some specs that were marked toThrowDeveloperError but the code didn't actually throw DeveloperErrors.
  • Loading branch information
shunter committed Dec 18, 2013
1 parent 0083faf commit da88547
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Specs/Core/Matrix4Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ defineSuite([
var matrix = new Matrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
expect(function() {
Matrix4.inverse(matrix);
}).toThrowDeveloperError();
}).toThrow();
});

it('static inverseTransformation throws without matrix parameter', function() {
Expand Down
4 changes: 2 additions & 2 deletions Specs/Core/TransformsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ defineSuite([
runs(function() {
expect(function() {
return Transforms.computeIcrfToFixedMatrix(time);
}).toThrowDeveloperError();
}).toThrow();
});
});

Expand All @@ -484,7 +484,7 @@ defineSuite([
runs(function() {
expect(function() {
return Transforms.computeIcrfToFixedMatrix(time);
}).toThrowDeveloperError();
}).toThrow();
});
});

Expand Down
34 changes: 29 additions & 5 deletions Specs/addDefaultMatchers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*global define*/
define([
'Core/defined',
'Core/DeveloperError',
'./equals'
], function(
defined,
DeveloperError,
equals) {
"use strict";

Expand Down Expand Up @@ -101,14 +103,36 @@ define([

toThrowDeveloperError : (function() {
if (debug) {
return function(func) {
var threw = false;
return function(expected) {
// based on the built-in Jasmine toThrow matcher
var result = false;
var exception;

if (typeof this.actual !== 'function') {
throw new Error('Actual is not a function');
}

try {
func();
this.actual();
} catch (e) {
threw = true;
exception = e;
}

if (exception) {
result = exception instanceof DeveloperError;
}
return threw;

var not = this.isNot ? "not " : "";

this.message = function() {
if (result) {
return ["Expected function " + not + "to throw DeveloperError, but it threw", exception.message || exception].join(' ');
} else {
return "Expected function to throw DeveloperError.";
}
};

return result;
};
}

Expand Down

0 comments on commit da88547

Please sign in to comment.