From 46d2c43da183819e6452ecc3cb158b2bf59ee1c2 Mon Sep 17 00:00:00 2001 From: Sheel Choksi Date: Tue, 18 Feb 2014 19:14:16 -0800 Subject: [PATCH] Revert "Use default failure message for toBeNaN" Forgot that NaN has special casing that it needs a custom error message for This reverts commit b6c03a34e7d7d0f0257388229708bf920b5c6a36. --- spec/core/matchers/toBeNaNSpec.js | 10 +++++++++- src/core/matchers/toBeNaN.js | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/core/matchers/toBeNaNSpec.js b/spec/core/matchers/toBeNaNSpec.js index c1229e6a..c0cbcc5d 100644 --- a/spec/core/matchers/toBeNaNSpec.js +++ b/spec/core/matchers/toBeNaNSpec.js @@ -1,10 +1,11 @@ describe("toBeNaN", function() { - it("passes for NaN", function() { + it("passes for NaN with a custom .not fail", function() { var matcher = j$.matchers.toBeNaN(), result; result = matcher.compare(Number.NaN); expect(result.pass).toBe(true); + expect(result.message).toEqual("Expected actual not to be NaN."); }); it("fails for anything not a NaN", function() { @@ -26,4 +27,11 @@ describe("toBeNaN", function() { result = matcher.compare(Number.POSITIVE_INFINITY); expect(result.pass).toBe(false); }); + + it("has a custom message on failure", function() { + var matcher = j$.matchers.toBeNaN(), + result = matcher.compare(0); + + expect(result.message).toEqual("Expected 0 to be NaN."); + }); }); diff --git a/src/core/matchers/toBeNaN.js b/src/core/matchers/toBeNaN.js index f1e1b373..a8b0c270 100644 --- a/src/core/matchers/toBeNaN.js +++ b/src/core/matchers/toBeNaN.js @@ -7,6 +7,12 @@ getJasmineRequireObj().toBeNaN = function(j$) { pass: (actual !== actual) }; + if (result.pass) { + result.message = "Expected actual not to be NaN."; + } else { + result.message = "Expected " + j$.pp(actual) + " to be NaN."; + } + return result; } };