Matchers & Matchers specs now broken up into individual files. There is now a requireMatchers jasmineRequire function to attach matchers properly.

This commit is contained in:
Davis W. Frank
2013-06-02 22:22:25 -07:00
parent 3271dc8838
commit d53002c63a
42 changed files with 1341 additions and 1173 deletions
+65
View File
@@ -0,0 +1,65 @@
getJasmineRequireObj().toThrow = function() {
function toThrow() {
return {
compare: function(actual, expected) {
var result = { pass: false },
exception;
if (typeof actual != "function") {
throw new Error("Actual is not a Function");
}
if (expectedCannotBeTreatedAsException()) {
throw new Error("Expected cannot be treated as an exception.");
}
try {
actual();
} catch (e) {
exception = new Error(e);
}
if (!exception) {
result.message = "Expected function to throw an exception.";
return result;
}
if (void 0 == expected) {
result.pass = true;
result.message = "Expected function not to throw an exception.";
} else if (exception.message == expected) {
result.pass = true;
result.message = "Expected function not to throw an exception \"" + expected + "\".";
} else if (exception.message == expected.message) {
result.pass = true;
result.message = "Expected function not to throw an exception \"" + expected.message + "\".";
} else if (expected instanceof RegExp) {
if (expected.test(exception.message)) {
result.pass = true;
result.message = "Expected function not to throw an exception matching " + expected + ".";
} else {
result.pass = false;
result.message = "Expected function to throw an exception matching " + expected + ".";
}
} else {
result.pass = false;
result.message = "Expected function to throw an exception \"" + (expected.message || expected) + "\".";
}
return result;
function expectedCannotBeTreatedAsException() {
return !(
(void 0 == expected) ||
(expected instanceof Error) ||
(typeof expected == "string") ||
(expected instanceof RegExp)
);
}
}
};
}
return toThrow;
};