How can you unit test Leaflet JS maps?
I have been working a bit more on testing and using Leaflet.
Currently I am using QUnit to run the tests.
I currently have to open it in a browser to see if it is working, maybe someone else knows how to run QUnit via commandline.
Before I wrote and ran my tests I took a look at the Leafletjs docs page and just started exploring the different js objects with the developer tools console on google chrome.
Leaflet docs: http://leafletjs.com/reference-1.0.0.html
Example tests from my QUnit tests.js file:
QUnit.test("map default options", function( assert ) assert.equal(myMap.getCenter().toString(),
"LatLng(0, 8.846)",
"The map is centered at the ZMT's longitude, and the equator"
);
assert.equal(myMap.getZoom(),
2,
"The default zoom is set to 2"
);
});
QUnit.test("baseLayer layerGroup", function( assert ) {
assert.equal(baseLayer.getLayers().length,
1,
"There is just one layer in 'baseLayer' layerGroup"
);
assert.equal(baseLayer.getLayers()[0]._url,
"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
"The url of the layer leads to the correct openstreet map tiles"
);
assert.equal(baseLayer.getLayers()[0].options.attribution,
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
"The attribution for the layer is correct"
);
assert.equal(baseLayer.getLayers()[0].options.minZoom,
0,
"The default minimum zoom is set to 0"
);
assert.equal(baseLayer.getLayers()[0].options.maxZoom,
19,
"The default maximum zoom is set to 19"
);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With