aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVojta Jina2013-05-24 15:55:11 -0700
committerBrian Ford2013-08-12 16:23:39 -0700
commit2b90ef16942496e78b6b97cd4814f1b84db27164 (patch)
tree4f9cd127da952c47767eba29217310e8effe9498
parent099138fb9a94178d3d82568fbda28d0c87443de9 (diff)
downloadangular.js-2b90ef16942496e78b6b97cd4814f1b84db27164.tar.bz2
test(matchers): update toThrow matcher
-rw-r--r--test/matchers.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/matchers.js b/test/matchers.js
index 3630c3b1..8e4be118 100644
--- a/test/matchers.js
+++ b/test/matchers.js
@@ -151,3 +151,38 @@ beforeEach(function() {
});
});
+
+
+// TODO(vojta): remove this once Jasmine in Karma gets updated
+// https://github.com/pivotal/jasmine/blob/c40b64a24c607596fa7488f2a0ddb98d063c872a/src/core/Matchers.js#L217-L246
+// This toThrow supports RegExps.
+jasmine.Matchers.prototype.toThrow = function(expected) {
+ var result = false;
+ var exception, exceptionMessage;
+ if (typeof this.actual != 'function') {
+ throw new Error('Actual is not a function');
+ }
+ try {
+ this.actual();
+ } catch (e) {
+ exception = e;
+ }
+
+ if (exception) {
+ exceptionMessage = exception.message || exception;
+ result = (isUndefined(expected) || this.env.equals_(exceptionMessage, expected.message || expected) || (jasmine.isA_("RegExp", expected) && expected.test(exceptionMessage)));
+ }
+
+ var not = this.isNot ? "not " : "";
+ var regexMatch = jasmine.isA_("RegExp", expected) ? " an exception matching" : "";
+
+ this.message = function() {
+ if (exception) {
+ return ["Expected function " + not + "to throw" + regexMatch, expected ? expected.message || expected : "an exception", ", but it threw", exceptionMessage].join(' ');
+ } else {
+ return "Expected function to throw an exception.";
+ }
+ };
+
+ return result;
+};