Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically created script causes timer to fire prematurely #1263

Open
wbyoung opened this issue Oct 14, 2015 · 0 comments
Open

Dynamically created script causes timer to fire prematurely #1263

wbyoung opened this issue Oct 14, 2015 · 0 comments

Comments

@wbyoung
Copy link

wbyoung commented Oct 14, 2015

The following has scripts in two files. The first has a dynamically created script and also sets a timeout. The second simply logs.

If you remove the script that's added dynamically, the timer fires after the second file is loaded (as expected).

var jsdom = require('jsdom');

var js1 =  'var script = document.createElement("script");'
    + 'script.src = "http://code.jquery.com/jquery-1.11.3.min.js";'
    + 'document.head.appendChild(script);'
    + 'console.log("first file loaded");'
    + 'setTimeout(function() { console.log("timeout running"); });';

var js2 = 'console.log("second file loaded");';

jsdom.env({
    html: '<html><head></head><body></body></html>',
    src: [js1, js2],
    virtualConsole: jsdom.createVirtualConsole().sendTo(console),
    done: function() {
        // set a timeout so process doesn't exit until timeout runs
        setTimeout(function() {}, 100);
    }
});

Expected output:

first file loaded
second file loaded
timeout running

Actual output:

first file loaded
timeout running
second file loaded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants