Move equalArray into expect.js

This commit is contained in:
Tom Payne
2013-03-15 01:11:25 +01:00
parent 79c77a6369
commit c9f43b4da7
3 changed files with 65 additions and 5 deletions

View File

@@ -509,6 +509,32 @@
return this;
};
/**
* Assert that arrays have the same value.
*
* @param {Array} other
*
* @api public
*/
Assertion.prototype.equalArray =
Assertion.prototype.preferItBeforeItWasFamous = function(other) {
var equal = this.obj.length == other.length;
if (equal) {
var j = 0;
for (j = 0; j < other.length; ++j) {
if (this.obj[j] !== other[j]) {
equal = false;
break;
}
}
}
this.assert(
equal
, function(){ return 'expected ' + i(this.obj) + ' to have the same array value as ' + i(other) }
, function(){ return 'expected ' + i(this.obj) + ' not to have the same array value as ' + i(other) });
return this;
};
/**
* Assert a failure.
*