开发者

jsdom not loading external resources

I can't seem to get jsdom to execute external scripts and I can't seem to find any concrete examples. I don't get any error when I call my testing function, but nothing happens.

This is my code:

    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());
    });

This is the html its loading:

<html>
    <head>
            <script type="te开发者_StackOverflow社区xt/javascript" src="stuff.js"></script>
    </head>
    <body>
    Hi there

    <div id="a1">
    </div>

    <div id="a2">
    </div>

 </body>
</html>

My testing function:

function testing() {
    var a2 = document.getElementById("a2");
    a2.innerHTML = 'Second div';
    console.log("executed");
 }


Check out the jsdom docs

Try this before the rest of your code:

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 welcomes you: http://bit.ly/nodeIRC

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜