Merge branch 'charleshansen-to_contain_array_like_objects'

This commit is contained in:
slackersoft
2014-11-03 13:10:13 -08:00
3 changed files with 18 additions and 3 deletions

View File

@@ -2187,7 +2187,9 @@ getJasmineRequireObj().matchersUtil = function(j$) {
contains: function(haystack, needle, customTesters) {
customTesters = customTesters || [];
if (Object.prototype.toString.apply(haystack) === '[object Array]') {
if ((Object.prototype.toString.apply(haystack) === '[object Array]') ||
(!!haystack && !haystack.indexOf))
{
for (var i = 0; i < haystack.length; i++) {
if (eq(haystack[i], needle, [], [], customTesters)) {
return true;
@@ -2195,6 +2197,7 @@ getJasmineRequireObj().matchersUtil = function(j$) {
}
return false;
}
return !!haystack && haystack.indexOf(needle) >= 0;
},

View File

@@ -174,7 +174,7 @@ describe("matchersUtil", function() {
describe("contains", function() {
it("passes when expected is a substring of actual", function() {
expect(j$.matchersUtil.contains("ABC", "B")).toBe(true);
expect(j$.matchersUtil.contains("ABC", "BC")).toBe(true);
});
it("fails when expected is a not substring of actual", function() {
@@ -207,6 +207,15 @@ describe("matchersUtil", function() {
it("fails when actual is null", function() {
expect(j$.matchersUtil.contains(null, 'A')).toBe(false);
});
it("passes with array-like objects", function() {
var capturedArgs = null;
function testFunction(){
capturedArgs = arguments;
}
testFunction('foo', 'bar');
expect(j$.matchersUtil.contains(capturedArgs, 'bar')).toBe(true);
});
});
describe("buildMessage", function() {

View File

@@ -11,7 +11,9 @@ getJasmineRequireObj().matchersUtil = function(j$) {
contains: function(haystack, needle, customTesters) {
customTesters = customTesters || [];
if (Object.prototype.toString.apply(haystack) === '[object Array]') {
if ((Object.prototype.toString.apply(haystack) === '[object Array]') ||
(!!haystack && !haystack.indexOf))
{
for (var i = 0; i < haystack.length; i++) {
if (eq(haystack[i], needle, [], [], customTesters)) {
return true;
@@ -19,6 +21,7 @@ getJasmineRequireObj().matchersUtil = function(j$) {
}
return false;
}
return !!haystack && haystack.indexOf(needle) >= 0;
},