Revert removal of compare nesting

Since we want the user to be able to pass a negative comparison function, the extra layer of wrapping is now needed
This commit is contained in:
Kyriacos Souroullas and Sheel Choksi
2013-10-28 13:49:54 -07:00
parent dd8a455f91
commit e346e7dcc1
37 changed files with 493 additions and 435 deletions
+31 -29
View File
@@ -1,42 +1,44 @@
getJasmineRequireObj().toThrow = function(j$) {
function toThrow(util) {
return function(actual, expected) {
var result = { pass: false },
threw = false,
thrown;
return {
compare: 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) + ".";
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;
}
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;
};
}