Tests for getFeatures method

This commit is contained in:
Tim Schaub
2013-11-19 15:38:19 -07:00
parent 1f6d9fc5ae
commit 3bcd4bf833

View File

@@ -63,6 +63,41 @@ describe('ol.source.Vector', function() {
source.addFeatures(features);
expect(source.getFeatures()).to.eql(features);
});
});
describe('#getFeatures()', function() {
it('gets features cached on the source', function() {
var source = new ol.source.Vector({
features: [new ol.Feature()]
});
source.addFeatures([new ol.Feature()]);
var features = source.getFeatures();
expect(features).to.be.an('array');
expect(features).to.have.length(2);
});
it('accepts a filter function', function() {
var features = [
new ol.Feature({name: 'a'}),
new ol.Feature({name: 'b'}),
new ol.Feature({name: 'c'}),
new ol.Feature({name: 'd'})
];
var source = new ol.source.Vector({features: features});
var results = source.getFeatures(function(feature) {
return feature.get('name') > 'b';
});
expect(results).to.be.an('array');
expect(results).to.have.length(2);
expect(results).to.contain(features[2]);
expect(results).to.contain(features[3]);
});
});
describe('featurechange event', function() {