Variable reference from external script in jsdom

432 views Asked by At

Below is the minimal example of jsdom code which uses the script parameter. Despite of all the attempts trying to find out a way to refer to the external JSs, I keep getting this

ReferenceError: exVar is not defined

Does anyone know what is the problem here and how to fix it?

stackOverTest.js

var jsdom = require("jsdom");

jsdom.env({
    "html": "<html><body></body></html>",
    scripts: [__dirname + "exScript.js"],
    done: function(er, win) {
    console.log("exVar: ", exVar);
    }
});

exScript.js

var exVar = "test";
1

There are 1 answers

4
stdob-- On BEST ANSWER

You need use win scope: console.log("exVar: ", win.exVar); and __dirname + "/exScript.js"