I installed jsdom via npm and required it in my testfile.
Everything is fine so far. Then I try to run an example from the documentation:
var jsdom = require("jsdom").jsdom;
var document = jsdom("hello world");
var window = document.parentWindow;
console.log(window.document.innerHTML);
// output: "<html><head></head><body>hello world</body></html>"
console.log(window.innerWidth);
// output: 1024
console.log(typeof window.document.getElementsByClassName);
// outputs: function
I get the two last outputs right, but the first one doesn`t work for me.

I also tried to attach the document and the window from jsdom to the node global object, but nothing changes here:
var jsdom = require("jsdom").jsdom;
global.document = jsdom("hello world");
global.window = document.parentWindow;
console.log(window.document.innerHTML);
// output: "<html><head></head><body>hello world</body></html>"
console.log(window.innerWidth);
// output: 1024
console.log(typeof window.document.getElementsByClassName);
// outputs: function
I can`t even find something like innerHTML when I look into the whole jsdom-object.
Would be awesome if anybody can tell me the problem.
Thanks a lot
Max
Hey me again ^^,
found the problem. Would be helpful if the example in the documentation actually would be a working example.
Something like this maybe:
var jsdom = require("jsdom").jsdom;
var document = jsdom("<div class='selector'><div class='innerselector'></div>");
var window = document.parentWindow;
console.log(window.document.querySelector('body').innerHTML);
// output: "<div class="selector"><div class="innerselector"></div></div>"
console.log(window.innerWidth);
// output: 1024
console.log(typeof window.document.getElementsByClassName);
// outputs: function
cheers Max
Most helpful comment
Hey me again ^^,
found the problem. Would be helpful if the example in the documentation actually would be a working example.
Something like this maybe:
cheers Max