Merge branch 'arrayContaining-actuals-must-be-arrays' of https://github.com/divido/jasmine
* Merges #1746 from @divido * Fixes #1745
This commit is contained in:
@@ -2252,6 +2252,13 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
|
|||||||
throw new Error('You must provide an array to arrayContaining, not ' + j$.pp(this.sample) + '.');
|
throw new Error('You must provide an array to arrayContaining, not ' + j$.pp(this.sample) + '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the actual parameter is not an array, we can fail immediately, since it couldn't
|
||||||
|
// possibly be an "array containing" anything. However, we also want an empty sample
|
||||||
|
// array to match anything, so we need to double-check we aren't in that case
|
||||||
|
if (!j$.isArray_(other) && this.sample.length > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0; i < this.sample.length; i++) {
|
for (var i = 0; i < this.sample.length; i++) {
|
||||||
var item = this.sample[i];
|
var item = this.sample[i];
|
||||||
if (!j$.matchersUtil.contains(other, item, customTesters)) {
|
if (!j$.matchersUtil.contains(other, item, customTesters)) {
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ describe("ArrayContaining", function() {
|
|||||||
expect(containing.asymmetricMatch(["bar"])).toBe(false);
|
expect(containing.asymmetricMatch(["bar"])).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not match when the actual is not an array", function() {
|
||||||
|
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
||||||
|
|
||||||
|
expect(containing.asymmetricMatch("foo")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it("jasmineToStrings itself", function() {
|
it("jasmineToStrings itself", function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining([]);
|
var containing = new jasmineUnderTest.ArrayContaining([]);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,13 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
|
|||||||
throw new Error('You must provide an array to arrayContaining, not ' + j$.pp(this.sample) + '.');
|
throw new Error('You must provide an array to arrayContaining, not ' + j$.pp(this.sample) + '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the actual parameter is not an array, we can fail immediately, since it couldn't
|
||||||
|
// possibly be an "array containing" anything. However, we also want an empty sample
|
||||||
|
// array to match anything, so we need to double-check we aren't in that case
|
||||||
|
if (!j$.isArray_(other) && this.sample.length > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0; i < this.sample.length; i++) {
|
for (var i = 0; i < this.sample.length; i++) {
|
||||||
var item = this.sample[i];
|
var item = this.sample[i];
|
||||||
if (!j$.matchersUtil.contains(other, item, customTesters)) {
|
if (!j$.matchersUtil.contains(other, item, customTesters)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user