mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
test(matchers): update toThrow matcher
This commit is contained in:
parent
099138fb9a
commit
2b90ef1694
1 changed files with 35 additions and 0 deletions
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue