@videsk/window-node-polyfill

Polyfill of window in node js for testing purpose

Usage no npm install needed!

<script type="module">
  import videskWindowNodePolyfill from 'https://cdn.skypack.dev/@videsk/window-node-polyfill';
</script>

README

Window polyfill for NodeJS

This library was designed to use in Node tesitng environment like mocha testing. If you need test code that use window but not DOM elements you maybe need install.

If you don't use a window polyfill you will get an error like this:

window is not defined

How to use

First install as dev dependency, never use in production server:

npm i @videsk/window-node-polyfill -D

Only need add on teh top of the test file, like this:

require('@videsk/window-node-polyfill');
...

Then you can access to the current properties:

  • localStorage
  • sessionStorage

For both cases to access to them is with:

// window.localStorage or window.sessionStorage
window.localStorage.getItem('my-key');
window.localStorage.setItem('my-key', 'my-value');
window.localStorage.removeItem('my-key');

Contributions

If you want add more properties, you're welcome, so send you PR or issue with feature request.

Copyrights

LGPL-2.1 License - By Videskā„¢