Remove an extra layer of wrapping for matchers/custom matchers
Helps reduce how nested custom matchers have to be for users as well as Jasmine internal matchers [#59161378]
This commit is contained in:
@@ -1,44 +1,42 @@
|
||||
getJasmineRequireObj().toThrow = function(j$) {
|
||||
|
||||
function toThrow(util) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
var result = { pass: false },
|
||||
threw = false,
|
||||
thrown;
|
||||
return function(actual, expected) {
|
||||
var result = { pass: false },
|
||||
threw = false,
|
||||
thrown;
|
||||
|
||||
if (typeof actual != "function") {
|
||||
throw new Error("Actual is not a Function");
|
||||
}
|
||||
if (typeof actual != "function") {
|
||||
throw new Error("Actual is not a Function");
|
||||
}
|
||||
|
||||
try {
|
||||
actual();
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
thrown = e;
|
||||
}
|
||||
try {
|
||||
actual();
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
thrown = e;
|
||||
}
|
||||
|
||||
if (!threw) {
|
||||
result.message = "Expected function to throw an exception.";
|
||||
return result;
|
||||
}
|
||||
if (!threw) {
|
||||
result.message = "Expected function to throw an exception.";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (arguments.length == 1) {
|
||||
result.pass = true;
|
||||
result.message = "Expected function not to throw, but it threw " + j$.pp(thrown) + ".";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (util.equals(thrown, expected)) {
|
||||
result.pass = true;
|
||||
result.message = "Expected function not to throw " + j$.pp(expected) + ".";
|
||||
} else {
|
||||
result.message = "Expected function to throw " + j$.pp(expected) + ", but it threw " + j$.pp(thrown) + ".";
|
||||
}
|
||||
if (arguments.length == 1) {
|
||||
result.pass = true;
|
||||
result.message = "Expected function not to throw, but it threw " + j$.pp(thrown) + ".";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (util.equals(thrown, expected)) {
|
||||
result.pass = true;
|
||||
result.message = "Expected function not to throw " + j$.pp(expected) + ".";
|
||||
} else {
|
||||
result.message = "Expected function to throw " + j$.pp(expected) + ", but it threw " + j$.pp(thrown) + ".";
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user