如何对Leaflet JS映射进行单元测试?

编程入门 行业动态 更新时间:2024-10-24 21:32:57
本文介绍了如何对Leaflet JS映射进行单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何对 Leaflet JS 地图进行单元测试?

How can you unit test Leaflet JS maps?

推荐答案

我真的在同一个问题上挣扎.这是使用js测试库"mocha"进行的一些测试的链接: 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': 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');

Node.js传单错误

在处理了该问题之后,我遇到了诸如'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映射进行单元测试?

本文发布于:2023-11-16 14:24:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605090.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   Leaflet   JS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!