Fix ol.Collection#push return value
This commit is contained in:
@@ -145,13 +145,13 @@ ol.Collection.prototype.pop = function() {
|
||||
/**
|
||||
* Insert the provided element at the end of the collection.
|
||||
* @param {T} elem Element.
|
||||
* @return {number} Length.
|
||||
* @return {number} New length of the collection.
|
||||
* @api stable
|
||||
*/
|
||||
ol.Collection.prototype.push = function(elem) {
|
||||
var n = this.array_.length;
|
||||
var n = this.getLength();
|
||||
this.insertAt(n, elem);
|
||||
return n;
|
||||
return this.getLength();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -31,11 +31,23 @@ describe('ol.collection', function() {
|
||||
|
||||
describe('push to a collection', function() {
|
||||
it('adds elements to the collection', function() {
|
||||
collection.push(1);
|
||||
expect(collection.getLength()).to.eql(1);
|
||||
var length = collection.push(1);
|
||||
expect(collection.getLength()).to.eql(length);
|
||||
expect(collection.getArray()).to.eql([1]);
|
||||
expect(collection.item(0)).to.eql(1);
|
||||
});
|
||||
it('returns the correct new length of the collection', function() {
|
||||
var length;
|
||||
ol.events.listen(collection, 'add', function(event) {
|
||||
if (event.element === 'remove_me') {
|
||||
collection.remove(event.element);
|
||||
}
|
||||
});
|
||||
length = collection.push('keep_me');
|
||||
expect(collection.getLength()).to.eql(length);
|
||||
length = collection.push('remove_me');
|
||||
expect(collection.getLength()).to.eql(length);
|
||||
});
|
||||
});
|
||||
|
||||
describe('pop from a collection', function() {
|
||||
@@ -236,8 +248,8 @@ describe('ol.collection', function() {
|
||||
ol.events.listen(collection, ol.Collection.EventType.ADD, function(e) {
|
||||
elem = e.element;
|
||||
});
|
||||
collection.push(1);
|
||||
expect(elem).to.eql(1);
|
||||
var length = collection.push(1);
|
||||
expect(elem).to.eql(length);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user