Files
jasmine/spec/core/asymmetric_equality/ArrayContainingSpec.js
Joey Parrish de7b7c029e Pass custom testers to asymmetric testers
This allows custom equality testers to affect asymmetric matches.
This avoid suprises when combining addCustomEqualityTester with
objectContaining or arrayContaining.

Closes #1138
2016-06-23 14:33:39 -07:00

53 lines
1.7 KiB
JavaScript

describe("ArrayContaining", function() {
it("matches any actual to an empty array", function() {
var containing = new jasmineUnderTest.ArrayContaining([]);
expect(containing.asymmetricMatch("foo")).toBe(true);
});
it("does not work when not passed an array", function() {
var containing = new jasmineUnderTest.ArrayContaining("foo");
expect(function() {
containing.asymmetricMatch([]);
}).toThrowError(/not 'foo'/);
});
it("matches when the item is in the actual", function() {
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
expect(containing.asymmetricMatch(["foo"])).toBe(true);
});
it("matches when additional items are in the actual", function() {
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
expect(containing.asymmetricMatch(["foo", "bar"])).toBe(true);
});
it("does not match when the item is not in the actual", function() {
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
expect(containing.asymmetricMatch(["bar"])).toBe(false);
});
it("jasmineToStrings itself", function() {
var containing = new jasmineUnderTest.ArrayContaining([]);
expect(containing.jasmineToString()).toMatch("<jasmine.arrayContaining");
});
it("uses custom equality testers", function() {
var tester = function(a, b) {
// All "foo*" strings match each other.
if (typeof a == "string" && typeof b == "string" &&
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
return true;
}
};
var containing = new jasmineUnderTest.ArrayContaining(["fooVal"]);
expect(containing.asymmetricMatch(["fooBar"], [tester])).toBe(true);
});
});