如何对Leaflet JS映射进行单元测试? [英] How can you unit test Leaflet JS maps?
问题描述
如何对 Leaflet JS 地图进行单元测试?
How can you unit test Leaflet JS maps?
推荐答案
我真的在同一个问题上挣扎.这是使用js测试库"mocha"进行的一些测试的链接: http://blog.mathieu-leplatre.info/test-your-leaflet-applications-with-mocha.html
I am really struggling with the same issue. Here is a link to some testing with the js test library 'mocha': http://blog.mathieu-leplatre.info/test-your-leaflet-applications-with-mocha.html
但是,我遇到了进一步的问题,试图调用传单的catch all'L'函数.首先是这样:
However, I ran into further issues trying to call leaflet's sort of catch all 'L' function. The first was this:
}(window, document));
^
ReferenceError: window is not defined
我用以下代码纠正了该问题:
I remedied that issue with this bit of code:
// 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的元素才能正常运行.
After I dealt with that issue, I am running into a problem with the actual functions, such as 'L.map(''). It seems that the function needs an element with an id to function correctly.
这是我收到的该函数的错误:
Here is the error I received for that function:
return (typeof id === 'string' ? document.getElementById(id) : id);
^
TypeError: document.getElementById is not a function
我希望这对您有所帮助,我当然还没有弄清楚.
I hope this helps you a little bit, I certainly still haven't figured it out.
这篇关于如何对Leaflet JS映射进行单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!