jsdom-sandbox
jsdom ❤️ the global namespace
Features
- DOM objects such as
document
andwindow
available globally - No globals leaking between unit tests
- Always a fresh instance of the DOM
Installation
The easiest way is to install jsdom-sandbox
as a devDependency
,
by running
npm install jsdom jsdom-sandbox --save-dev
How it works
This package is a thin wrapper around jsdom, taking care of exposing all global DOM properties during the test and cleaning up resources after the completed test.
The sandbox
function takes three parameters and the first two are used to create a new jsdom
instance each time the function is called:
html
, astring
containing html.options
, anobject
with options for customizingjsdom
.callback
, the wrapper function. This function has an optional parameter which is the actualjsdom
instance.
var dom = ; dom;
For a complete list of options and features, please refer to the jsdom official documentation.
Examples
tape
ES5 +var dom = ;var test = ; ;
tape
ES6 +;; ;
tape
Typescript +;; ;
Please note that jsdom-sandbox
ships with Typescript typings.
Licensing
This software is licensed with the MIT license.
© 2017-2018 Monounity, Erik Barke