diff --git a/spec/core/asymmetric_equality/ArrayContainingSpec.js b/spec/core/asymmetric_equality/ArrayContainingSpec.js new file mode 100644 index 00000000..a508ea94 --- /dev/null +++ b/spec/core/asymmetric_equality/ArrayContainingSpec.js @@ -0,0 +1,39 @@ +describe("ArrayContaining", function() { + it("matches any actual to an empty array", function() { + var containing = new j$.ArrayContaining([]); + + expect(containing.asymmetricMatch("foo")).toBe(true); + }); + + it("does not work when not passed an array", function() { + var containing = new j$.ArrayContaining("foo"); + + expect(function() { + containing.asymmetricMatch([]); + }).toThrowError(/not 'foo'/); + }); + + it("matches when the item is in the actual", function() { + var containing = new j$.ArrayContaining(["foo"]); + + expect(containing.asymmetricMatch(["foo"])).toBe(true); + }); + + it("matches when additional items are in the actual", function() { + var containing = new j$.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 j$.ArrayContaining(["foo"]); + + expect(containing.asymmetricMatch(["bar"])).toBe(false); + }); + + it("jasmineToStrings itself", function() { + var containing = new j$.ArrayContaining([]); + + expect(containing.jasmineToString()).toMatch(""; + }; + + return ArrayContaining; +}; diff --git a/src/core/base.js b/src/core/base.js index b0b3847c..f8291d3d 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -57,6 +57,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { return new j$.StringMatching(expected); }; + j$.arrayContaining = function(sample) { + return new j$.ArrayContaining(sample); + }; + j$.createSpy = function(name, originalFn) { var spyStrategy = new j$.SpyStrategy({ diff --git a/src/core/requireCore.js b/src/core/requireCore.js index 10de5590..73bf3c24 100644 --- a/src/core/requireCore.js +++ b/src/core/requireCore.js @@ -30,6 +30,7 @@ getJasmineRequireObj = (function (jasmineGlobal) { j$.JsApiReporter = jRequire.JsApiReporter(); j$.matchersUtil = jRequire.matchersUtil(j$); j$.ObjectContaining = jRequire.ObjectContaining(j$); + j$.ArrayContaining = jRequire.ArrayContaining(j$); j$.pp = jRequire.pp(j$); j$.QueueRunner = jRequire.QueueRunner(j$); j$.ReportDispatcher = jRequire.ReportDispatcher();