Merge pull request #379 from sheelc/toThrowError_fixup

Fix up refactoring mistake in toThrowError
This commit is contained in:
pivotalprivate
2013-06-05 09:54:12 -07:00
3 changed files with 16 additions and 6 deletions

View File

@@ -2107,7 +2107,7 @@ getJasmineRequireObj().toThrowError = function() {
}
if (errorType && message) {
if (util.equals(thrown, new errorType(message))) {
if (thrown.constructor == errorType && util.equals(thrown.message, message)) {
return pass("Expected function not to throw Error with message \"" + message + "\".");
} else {
return fail("Expected function to throw Error with message \"" + message + "\".");
@@ -2172,7 +2172,7 @@ getJasmineRequireObj().toThrowError = function() {
regexp = expected;
} else if (typeof expected == "string") {
message = expected;
} else if (typeof expected == "function" && new expected() instanceof Error) {
} else if (checkForAnErrorType(expected)) {
errorType = expected;
}
@@ -2180,7 +2180,7 @@ getJasmineRequireObj().toThrowError = function() {
throw new Error("Expected is not an Error, string, or RegExp.");
}
} else {
if (typeof arguments[1] == "function" && new arguments[1]() instanceof Error) {
if (checkForAnErrorType(arguments[1])) {
errorType = arguments[1];
} else {
throw new Error("Expected error type is not an Error.");
@@ -2195,6 +2195,16 @@ getJasmineRequireObj().toThrowError = function() {
}
}
}
function checkForAnErrorType(type) {
if (typeof type !== "function") {
return false;
}
var Surrogate = function() {};
Surrogate.prototype = type.prototype;
return (new Surrogate()) instanceof Error;
}
}
};
}

View File

@@ -25,7 +25,7 @@ describe("toThrowError", function() {
};
expect(function() {
matcher.compare(fn, "string", "foo");
matcher.compare(fn, void 0, "foo");
}).toThrow(new Error("Expected error type is not an Error.")); // TODO: this needs to change for self-test
});

View File

@@ -124,14 +124,14 @@ getJasmineRequireObj().toThrowError = function() {
}
function checkForAnErrorType(type) {
if (typeof expected == "function") {
if (typeof type !== "function") {
return false;
}
var Surrogate = function() {};
Surrogate.prototype = type.prototype;
return (new Surrogate()) instanceof Error;
};
}
}
};
}