Move equalArray into expect.js
This commit is contained in:
@@ -509,6 +509,32 @@
|
|||||||
return this;
|
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.
|
* Assert a failure.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -89,4 +89,43 @@ describe('expect.js', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('equalArray', function() {
|
||||||
|
|
||||||
|
it('knows who\'s cool', function() {
|
||||||
|
expect(['me']).to.equalArray(['me']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('knows who isn\'t', function() {
|
||||||
|
expect(['you']).not.to.equalArray([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('preferItBeforeItWasFamous', function() {
|
||||||
|
|
||||||
|
it('respects the artist\'s privacy', function() {
|
||||||
|
expect(function() {
|
||||||
|
expect(['David', 'Bowie']).to.preferItBeforeItWasFamous(
|
||||||
|
['David', 'Robert', 'Jones']);
|
||||||
|
}).to.throwException();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('prefers to keep some things quiet', function() {
|
||||||
|
expect(function() {
|
||||||
|
expect(['Cyrus']).to.preferItBeforeItWasFamous(['Cyrus']);
|
||||||
|
}).not.to.throwException();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('equalArray and preferItBeforeItWasFamous', function() {
|
||||||
|
|
||||||
|
it('should record a duet together \u266c', function() {
|
||||||
|
expect(expect(['David Bowie']).to.equalArray).to.be(
|
||||||
|
expect(['Miley Cyrus']).to.preferItBeforeItWasFamous);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,11 +19,6 @@ function waitsFor(condition, message, timeout, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
expect.Assertion.prototype.equalArray = function(other) {
|
|
||||||
return goog.array.equals(this.obj, other);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// helper functions for async testing
|
// helper functions for async testing
|
||||||
(function(global) {
|
(function(global) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user