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() {