Skip to content

Commit

Permalink
Array contains matcher fails when actual is not an array
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfcosta committed Dec 25, 2016
1 parent bec0b4f commit bd9d57f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sinon/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ match.array.endsWith = function (expectation) {

match.array.contains = function (expectation) {
return match(function (actual) {
return every.call(expectation, function (expectedElement) {
return typeOf(actual) === "array" && every.call(expectation, function (expectedElement) {
return indexOf.call(actual, expectedElement) !== -1;
});
}, "contains([" + arrayToString.call(expectation) + "])");
Expand Down
6 changes: 6 additions & 0 deletions test/match-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,12 @@ describe("sinonMatch", function () {
assert.isFalse(sinonMatch.array.contains([1, 2, 3]).test([1, 2]));
assert.isFalse(sinonMatch.array.contains([3]).test([1, 2]));
});

it("fails when passed a non-array object", function () {
var contains = sinonMatch.array.contains(["one", "three"]);

assert.isFalse(contains.test({0: "one", 1: "two", 2: "three", length: 3}));
});
});
});

Expand Down

0 comments on commit bd9d57f

Please sign in to comment.