Added toBeNaN matcher

This commit is contained in:
James Cracknell
2012-07-12 19:14:13 -06:00
parent dad4865fbf
commit f910df00bb
3 changed files with 45 additions and 0 deletions
+11
View File
@@ -1293,6 +1293,17 @@ jasmine.Matchers.prototype.toBeNull = function() {
return (this.actual === null); return (this.actual === null);
}; };
/**
* Matcher that compares the actual to NaN.
*/
jasmine.Matchers.prototype.toBeNaN = function() {
this.message = function() {
return [ "Expected " + jasmine.pp(this.actual) + " to be NaN." ];
};
return (this.actual !== this.actual);
};
/** /**
* Matcher that boolean not-nots the actual. * Matcher that boolean not-nots the actual.
*/ */
+23
View File
@@ -281,6 +281,29 @@ describe("jasmine.Matchers", function() {
expect(result.actual).toEqual(actual); expect(result.actual).toEqual(actual);
}); });
it("toBeNaN", function() {
expect(match(Number.NaN).toBeNaN()).toPass();
expect(match(0).toBeNaN()).toFail();
expect(match(1).toBeNaN()).toFail();
expect(match(null).toBeNaN()).toFail();
expect(match(Number.POSITIVE_INFINITY).toBeNaN()).toFail();
expect(match(Number.NEGATIVE_INFINITY).toBeNaN()).toFail();
expect(match('NaN').toBeNaN()).toFail();
});
it("toBeNaN to build an ExpectationResult", function() {
var actual = 'a';
var matcher = match(actual);
matcher.toBeNaN();
var result = lastResult();
expect(result.matcherName).toEqual("toBeNaN");
expect(result.passed()).toFail();
expect(result.message).toMatch("Expected 'a' to be NaN.");
expect(result.actual).toMatch(actual);
});
it("toBeFalsy", function() { it("toBeFalsy", function() {
expect(match(false).toBeFalsy()).toPass(); expect(match(false).toBeFalsy()).toPass();
expect(match(true).toBeFalsy()).toFail(); expect(match(true).toBeFalsy()).toFail();
+11
View File
@@ -150,6 +150,17 @@ jasmine.Matchers.prototype.toBeNull = function() {
return (this.actual === null); return (this.actual === null);
}; };
/**
* Matcher that compares the actual to NaN.
*/
jasmine.Matchers.prototype.toBeNaN = function() {
this.message = function() {
return [ "Expected " + jasmine.pp(this.actual) + " to be NaN." ];
};
return (this.actual !== this.actual);
};
/** /**
* Matcher that boolean not-nots the actual. * Matcher that boolean not-nots the actual.
*/ */