我有一些代码在浏览器中运行,作为对AJAX请求的响应:
var req = new XMLHttpRequest();
req.addEventListener('load', function(e) {
var xmlResponse = e.target.responseXML;
// a bunch of code that uses .querySelector and .querySelectorAll
// on xmlResponse to find nodes and then it
// calls .querySelector/.querySelectorAll on those nodes to find
// other nodes, or .textContent to read their content.
});
req.open('GET', url);
req.send();
我已经将解析的代码提取到一个单独的函数中,我想在Node中测试它,因为它更容易自动进行lint,test和bundle。
我遇到的问题是,在Node I中没有找到将XML文件解析为支持.querySelector()
,.querySelectorAll()
和.textContent()
的对象的方法,而我需要创建这样一个对象并将其传递给我要测试的函数。
有办法吗?我尝试了一些npm软件包,但没有找到提供此功能的软件包。