Argument matcher for an array containing at least the specified entries

This commit is contained in:
slackersoft
2013-10-03 18:21:47 -07:00
parent 6354ee17e5
commit b5b77b318a
7 changed files with 106 additions and 2 deletions
+51
View File
@@ -0,0 +1,51 @@
describe("ArrayContaining", function() {
it("matches any actual to an empty array", function() {
var containing = new j$.ArrayContaining([]);
expect(containing.jasmineMatches("foo")).toBe(true);
});
it("does not work when not passed an array", function() {
var containing = new j$.ArrayContaining("foo");
expect(function() {
containing.jasmineMatches([]);
}).toThrowError(/not 'foo'/);
});
it("matches when the item is in the actual", function() {
var containing = new j$.ArrayContaining(["foo"]);
expect(containing.jasmineMatches(["foo"])).toBe(true);
});
it("matches when additional items are in the actual", function() {
var containing = new j$.ArrayContaining(["foo"]);
expect(containing.jasmineMatches(["foo", "bar"])).toBe(true);
});
it("does not match when the item is not in the actual", function() {
var containing = new j$.ArrayContaining(["foo"]);
expect(containing.jasmineMatches(["bar"])).toBe(false);
});
it("mismatchValues parameter returns array with mismatched reason", function() {
var containing = new j$.ArrayContaining(["foo", "bar"]);
var mismatchKeys = [];
var mismatchValues = [];
containing.jasmineMatches([], mismatchKeys, mismatchValues);
expect(mismatchValues.length).toBe(1);
expect(mismatchValues[0]).toEqual("expected to have values ['foo','bar']")
});
it("jasmineToStrings itself", function() {
var containing = new j$.ArrayContaining([]);
expect(containing.jasmineToString()).toMatch("<jasmine.arrayContaining");
});
});
+1 -1
View File
@@ -61,4 +61,4 @@ describe("ObjectContaining", function() {
expect(containing.jasmineToString()).toMatch("<jasmine.objectContaining");
});
});
});
+6
View File
@@ -147,6 +147,12 @@ describe("matchersUtil", function() {
expect(j$.matchersUtil.equals(obj, new j$.ObjectContaining({foo: 3}))).toBe(true);
});
it("passes when ArrayContaining is used", function() {
var arr = ["foo", "bar"];
expect(j$.matchersUtil.equals(arr, new j$.ArrayContaining(["bar"]))).toBe(true);
});
it("passes when a custom equality matcher returns true", function() {
var tester = function(a, b) { return true; };