jsdom没有加载外部资源
问题描述:
我似乎无法得到jsdom执行外部脚本,我似乎无法找到任何具体的例子。当我打电话给我的测试功能时,我没有收到任何错误,但没有任何反应。jsdom没有加载外部资源
这是我的代码:
var window = jsdom.jsdom(body).createWindow();
jsdom.jQueryify(window, './lib/jquery.js', function() {
console.log(window.$("#a1").text());
window.testing();
console.log(window.$("#a2").text());
});
这是HTML它的加载:
<html>
<head>
<script type="text/javascript" src="stuff.js"></script>
</head>
<body>
Hi there
<div id="a1">
</div>
<div id="a2">
</div>
</body>
</html>
我的测试功能:
function testing() {
var a2 = document.getElementById("a2");
a2.innerHTML = 'Second div';
console.log("executed");
}
答
时退房jsdom docs
你的代码的其余部分之前,试试这个:
require('jsdom').defaultDocumentFeatures = {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script'],
MutationEvents : '2.0',
QuerySelector : false
}
var window = jsdom.jsdom(body).createWindow();
jsdom.jQueryify(window, './lib/jquery.js', function() {
console.log(window.$("#a1").text());
window.testing();
console.log(window.$("#a2").text());
});
/FYI#node.js的IRC欢迎您:http://bit.ly/nodeIRC
这个答案是最新的更新错后。 MutationEvents需要是“2.0”而不是false。 – 2012-01-20 07:32:06
@BjornTipling更新:) – DTrejo 2012-01-22 00:35:53