Permalink
Browse files

Contains is explicitly false if actual is undefined or null

Fix #627
  • Loading branch information...
1 parent 62212bb commit a1c109ea177c94d6d63dde842c37adce7ad792cd @slackersoft slackersoft committed Jul 18, 2014
Showing with 9 additions and 1 deletion.
  1. +8 −0 spec/core/matchers/matchersUtilSpec.js
  2. +1 −1 src/core/matchers/matchersUtil.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() {
@@ -19,7 +19,7 @@ getJasmineRequireObj().matchersUtil = function(j$) {
}
return false;
}
- return haystack.indexOf(needle) >= 0;
+ return !!haystack && haystack.indexOf(needle) >= 0;
},
buildFailureMessage: function() {

0 comments on commit a1c109e

Please sign in to comment.