Merge pull request #6220 from fredj/collection_push_length

Fix ol.Collection#push return value
This commit is contained in:
Frédéric Junod
2016-12-08 08:26:31 +01:00
committed by GitHub
2 changed files with 19 additions and 7 deletions

View File

@@ -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);
});
});