你怎麼能單元測試Leaflet JS地圖?你如何測試Leaflet JS地圖?
3
A
回答
4
我真的很苦惱同一個問題。這裏是一個鏈接到一些測試與js測試庫'摩卡': http://blog.mathieu-leplatre.info/test-your-leaflet-applications-with-mocha.html
然而,我遇到了進一步的問題,試圖調用傳單的類型捕獲所有'L'功能。第一次是這樣的:
}(window, document));
^
ReferenceError: window is not defined
我糾正這個問題有這段代碼:
// Create globals so leaflet can load
GLOBAL.window = {};
GLOBAL.document = {
documentElement: {
style: {}
},
getElementsByTagName: function() { return []; },
createElement: function() { return {}; }
};
GLOBAL.navigator = {
userAgent: 'nodejs'
};
GLOBAL.L = require('leaflet');
後,我處理了這個問題,我遇到了一個問題,與實際函數,如'L.map('')。看來這個函數需要一個帶有id的元素才能正常工作。
這是我該函數收到錯誤:
return (typeof id === 'string' ? document.getElementById(id) : id);
^
TypeError: document.getElementById is not a function
我希望這可以幫助你一點點,我肯定還沒有計算出來。
1
我一直在努力測試和使用Leaflet。
目前我正在使用QUnit來運行測試。
我目前必須在瀏覽器中打開它,看看它是否工作,也許別人知道如何通過命令行運行QUnit。
在我編寫並運行我的測試之前,我看了一下Leafletjs文檔頁面,並開始使用google chrome上的開發人員工具控制檯探索不同的js對象。
單張文檔:從我的QUnit tests.js文件 http://leafletjs.com/reference-1.0.0.html
示例測試:
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"
);
});
相關問題
- 1. 你會如何測試谷歌地圖?
- 2. 性能測試OpenLayers vs Leaflet
- 3. 如何將標記添加到地圖(Google JS api,Leaflet或Mapbox)?
- 4. Three.js + leaflet = 3D地圖?
- 5. 你如何測試你的emberjs路線?
- 6. 你如何編寫你的QTP測試?
- 7. 你如何測試DAL?
- 8. ASP.NET - 你如何測試WebControls?
- 9. 你如何測試權限?
- 10. 你會如何測試ExpressionVisitor?
- 11. 你如何測試你的Request.QueryString []變量?
- 12. 你如何測試你的Cocoa GUI?
- 13. 測試「地圖」
- 14. 你如何測試GWT代碼?
- 15. 你如何在Windows上測試Rails?
- 16. 你如何創建地圖的地圖?
- 17. Leaflet JS:隱藏地圖磁貼供應商的API密鑰
- 18. Android,如何測試Google地圖
- 19. 快速js測試視圖
- 20. 你如何在Django中測試formset?
- 21. 你如何測試非功能代碼?
- 22. 你如何測試小東西? (Eclipse Android)
- 23. 你如何測試依賴注入?
- 24. 你如何故意造成SoapFault測試?
- 25. 你如何測試Java EE代碼?
- 26. 你如何決定在測試套件中測試什麼?
- 27. 你如何快速地測試基準腳本
- 28. 你如何測試render_remote_content接收正確的當地人
- 29. 你如何測試CocoaPod代碼?
- 30. 如何在geoJson圖層上的Leaflet中模擬地圖?
你有什麼需要測試,到底是什麼? – IvanSanchez