小智 5
我真的在努力解决同样的问题.以下是使用js测试库'mocha'进行一些测试的链接:http: //blog.mathieu-leplatre.info/test-your-leaflet-applications-with-mocha.html
然而,我遇到了进一步的问题,试图调用传单的捕获所有'L'功能.首先是这个:
}(window, document));
^
ReferenceError: window is not defined
Run Code Online (Sandbox Code Playgroud)
我用这段代码解决了这个问题:
// 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');
Run Code Online (Sandbox Code Playgroud)
在我处理了这个问题之后,我遇到了实际函数的问题,比如'L.map('').似乎该函数需要一个具有id才能正常运行的元素.
这是我收到的该函数的错误:
return (typeof id === 'string' ? document.getElementById(id) : id);
^
TypeError: document.getElementById is not a function
Run Code Online (Sandbox Code Playgroud)
我希望这对你有所帮助,我当然还是没有想到它.