Detect an Error passed to done and add an expectation failure
- See #567
This commit is contained in:
@@ -5,7 +5,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
return function() {
|
||||
if (!called) {
|
||||
called = true;
|
||||
fn();
|
||||
fn.apply(null, arguments);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@@ -59,15 +59,20 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
var self = this, completedSynchronously = true,
|
||||
handleError = function handleError(error) {
|
||||
onException(error);
|
||||
next();
|
||||
next(error);
|
||||
},
|
||||
cleanup = once(function cleanup() {
|
||||
self.clearTimeout(timeoutId);
|
||||
self.globalErrors.popListener(handleError);
|
||||
}),
|
||||
next = once(function next() {
|
||||
next = once(function next(err) {
|
||||
cleanup();
|
||||
|
||||
if (j$.isError_(err)) {
|
||||
self.fail(err);
|
||||
errored = true;
|
||||
}
|
||||
|
||||
function runNext() {
|
||||
if (self.completeOnFirstError && errored) {
|
||||
self.skipToCleanup(iterativeIndex);
|
||||
|
||||
@@ -85,6 +85,17 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
return j$.getType_(value) === '[object ' + typeName + ']';
|
||||
};
|
||||
|
||||
j$.isError_ = function(value) {
|
||||
if (value instanceof Error) {
|
||||
return true;
|
||||
}
|
||||
if (value && value.constructor && value.constructor.constructor &&
|
||||
(value instanceof (value.constructor.constructor('return this')()).Error)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
j$.getType_ = function(value) {
|
||||
return Object.prototype.toString.apply(value);
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ getJasmineRequireObj().toThrowError = function(j$) {
|
||||
thrown = e;
|
||||
}
|
||||
|
||||
if (!isErrorObject(thrown)) {
|
||||
if (!j$.isError_(thrown)) {
|
||||
return fail(function() { return 'Expected function to throw an Error, but it threw ' + j$.pp(thrown) + '.'; });
|
||||
}
|
||||
|
||||
@@ -144,18 +144,7 @@ getJasmineRequireObj().toThrowError = function(j$) {
|
||||
|
||||
var Surrogate = function() {};
|
||||
Surrogate.prototype = type.prototype;
|
||||
return isErrorObject(new Surrogate());
|
||||
}
|
||||
|
||||
function isErrorObject(thrown) {
|
||||
if (thrown instanceof Error) {
|
||||
return true;
|
||||
}
|
||||
if (thrown && thrown.constructor && thrown.constructor.constructor &&
|
||||
(thrown instanceof (thrown.constructor.constructor('return this')()).Error)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return j$.isError_(new Surrogate());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user