Leaflet/spec/suites/layer/LayerGroupSpec.js

72 lines
1.6 KiB
JavaScript
Raw Normal View History

describe('LayerGroup', function () {
2013-12-14 06:51:37 +08:00
describe("#hasLayer", function () {
it("returns false when passed undefined, null, or false", function () {
var lg = L.layerGroup();
expect(lg.hasLayer(undefined)).to.equal(false);
expect(lg.hasLayer(null)).to.equal(false);
expect(lg.hasLayer(false)).to.equal(false);
});
});
describe("#addLayer", function () {
it('adds a layer', function () {
var lg = L.layerGroup(),
2015-09-25 18:55:37 +08:00
marker = L.marker([0, 0]);
2013-03-02 05:49:20 +08:00
expect(lg.addLayer(marker)).to.eql(lg);
2013-03-02 05:49:20 +08:00
expect(lg.hasLayer(marker)).to.be(true);
});
});
2013-12-14 06:51:37 +08:00
describe("#removeLayer", function () {
it('removes a layer', function () {
var lg = L.layerGroup(),
2015-09-25 18:55:37 +08:00
marker = L.marker([0, 0]);
lg.addLayer(marker);
2013-03-02 05:49:20 +08:00
expect(lg.removeLayer(marker)).to.eql(lg);
2013-03-02 05:49:20 +08:00
expect(lg.hasLayer(marker)).to.be(false);
});
});
2013-12-14 06:51:37 +08:00
describe("#clearLayers", function () {
it('removes all layers', function () {
var lg = L.layerGroup(),
2015-09-25 18:55:37 +08:00
marker = L.marker([0, 0]);
lg.addLayer(marker);
2013-03-02 05:49:20 +08:00
expect(lg.clearLayers()).to.eql(lg);
2013-03-02 05:49:20 +08:00
expect(lg.hasLayer(marker)).to.be(false);
});
});
2013-12-14 06:51:37 +08:00
describe("#getLayers", function () {
it('gets all layers', function () {
var lg = L.layerGroup(),
2015-09-25 18:55:37 +08:00
marker = L.marker([0, 0]);
lg.addLayer(marker);
2013-03-02 05:49:20 +08:00
expect(lg.getLayers()).to.eql([marker]);
});
});
2013-12-14 06:51:37 +08:00
describe("#eachLayer", function () {
it('iterates over all layers', function () {
var lg = L.layerGroup(),
2015-09-25 18:55:37 +08:00
marker = L.marker([0, 0]),
ctx = {foo: 'bar'};
lg.addLayer(marker);
lg.eachLayer(function (layer) {
2013-03-02 05:49:20 +08:00
expect(layer).to.eql(marker);
expect(this).to.eql(ctx);
}, ctx);
});
});
});