diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 56fe8fc9..a3ee39b4 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -52,6 +52,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(); @@ -160,6 +161,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({ @@ -2178,6 +2183,32 @@ getJasmineRequireObj().Anything = function(j$) { return Anything; }; +getJasmineRequireObj().ArrayContaining = function(j$) { + function ArrayContaining(sample) { + this.sample = sample; + } + + ArrayContaining.prototype.asymmetricMatch = function(other) { + var className = Object.prototype.toString.call(this.sample); + if (className !== '[object Array]') { throw new Error('You must provide an array to arrayContaining, not \'' + this.sample + '\'.'); } + + for (var i = 0; i < this.sample.length; i++) { + var item = this.sample[i]; + if (!j$.matchersUtil.contains(other, item)) { + return false; + } + } + + return true; + }; + + ArrayContaining.prototype.jasmineToString = function () { + return ''; + }; + + return ArrayContaining; +}; + getJasmineRequireObj().ObjectContaining = function(j$) { function ObjectContaining(sample) { diff --git a/src/core/asymmetric_equality/ArrayContaining.js b/src/core/asymmetric_equality/ArrayContaining.js index 5414beac..dbc7b0b8 100644 --- a/src/core/asymmetric_equality/ArrayContaining.js +++ b/src/core/asymmetric_equality/ArrayContaining.js @@ -5,7 +5,7 @@ getJasmineRequireObj().ArrayContaining = function(j$) { ArrayContaining.prototype.asymmetricMatch = function(other) { var className = Object.prototype.toString.call(this.sample); - if (className !== "[object Array]") { throw new Error("You must provide an array to arrayContaining, not '" + this.sample + "'."); } + if (className !== '[object Array]') { throw new Error('You must provide an array to arrayContaining, not \'' + this.sample + '\'.'); } for (var i = 0; i < this.sample.length; i++) { var item = this.sample[i]; @@ -18,7 +18,7 @@ getJasmineRequireObj().ArrayContaining = function(j$) { }; ArrayContaining.prototype.jasmineToString = function () { - return ""; + return ''; }; return ArrayContaining;