diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 6bac2236..02cb7846 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1293,6 +1293,17 @@ jasmine.Matchers.prototype.toBeNull = function() { 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. */ diff --git a/spec/core/MatchersSpec.js b/spec/core/MatchersSpec.js index 7be2b814..219776e1 100644 --- a/spec/core/MatchersSpec.js +++ b/spec/core/MatchersSpec.js @@ -281,6 +281,29 @@ describe("jasmine.Matchers", function() { 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() { expect(match(false).toBeFalsy()).toPass(); expect(match(true).toBeFalsy()).toFail(); diff --git a/src/core/Matchers.js b/src/core/Matchers.js index 7303facb..1e5be907 100644 --- a/src/core/Matchers.js +++ b/src/core/Matchers.js @@ -150,6 +150,17 @@ jasmine.Matchers.prototype.toBeNull = function() { 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. */