From a1c109ea177c94d6d63dde842c37adce7ad792cd Mon Sep 17 00:00:00 2001 From: slackersoft Date: Fri, 18 Jul 2014 13:18:22 -0700 Subject: [PATCH] Contains is explicitly false if actual is undefined or null Fix #627 --- spec/core/matchers/matchersUtilSpec.js | 8 ++++++++ src/core/matchers/matchersUtil.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index ca88a1ca..4a981a13 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -199,6 +199,14 @@ describe("matchersUtil", function() { expect(j$.matchersUtil.contains([1, 2], 2, [customTester])).toBe(true); }); + + it("fails when actual is undefined", function() { + expect(j$.matchersUtil.contains(undefined, 'A')).toBe(false); + }); + + it("fails when actual is null", function() { + expect(j$.matchersUtil.contains(null, 'A')).toBe(false); + }); }); describe("buildMessage", function() { diff --git a/src/core/matchers/matchersUtil.js b/src/core/matchers/matchersUtil.js index 0948e9f5..b6fb8383 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -19,7 +19,7 @@ getJasmineRequireObj().matchersUtil = function(j$) { } return false; } - return haystack.indexOf(needle) >= 0; + return !!haystack && haystack.indexOf(needle) >= 0; }, buildFailureMessage: function() {