window
Exports a jsdom
window object.
Exports a jsdom window object. This is useful for enabling browser modules to run in Node.js or testing browser modules in any Node.js test framework.
Install
npm install --save window
Or if you're just using for testing you'll probably want:
npm install --save-dev window
Usage
const Window = require('window');
const window = new Window();
const div = window.document.createElement('div');
div instanceof window.HTMLElement
Because window
is just a normal JavaScript object it can be used more efficiently with object destructuring.
const { document } = new Window();
document.body.innerHTML = '<div class="foo">Hi!</div>';
document.body.querySelector('.foo').textContent;
License
MIT © Luke Childs