Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

window-mock

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

window-mock - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

2

package.json
{
"name": "window-mock",
"version": "0.0.4",
"version": "0.0.5",
"description": "A light-weight window mock for Node/io.js testing",

@@ -5,0 +5,0 @@ "main": "lib/window-mock.js",

@@ -8,6 +8,6 @@ [![NPM](https://nodei.co/npm/window-mock.png?mini=true)](https://nodei.co/npm/window-mock/)

# window-mock
A light-weight window-mock for node/ io.js testing
A light-weight window-mock for node/ io.js unit-testing written in ES6
Install via:
## Install
```shell

@@ -17,3 +17,6 @@ npm install window-mock --save-dev

Use it in your unit tests:
## Usage (ES6+)
Once you created a WindowMock-Instance the mock should behave exactly as the
browser's window object.
```javascript

@@ -26,3 +29,3 @@ import test from 'tape';

let
windowMock = new WindowMock(),
windowMock = new WindowMock();

@@ -40,1 +43,30 @@ windowMock.localStorage.setItem('key', 'value');

```
## Usage (ES5/ Javascript)
```javascript
var
test = require('tape'),
WindowMock = require('window-mock');
test(`Some window interaction unit test`, function(t) {
var
windowMock = new WindowMock();
windowMock.localStorage.setItem('key', 'value');
t.equal(
windowMock.localStorage.getItem('key'),
'value',
'should set `key` to `value`'
);
t.end();
});
```
## Fork and Pull-request
This module was built for unit-test mocking the browser's window-object in
my other projects. It's far from complete and will grow once needed.
Feel free to fork and pull-request!

@@ -8,5 +8,33 @@ import test from 'tape';

test(`${name}: Window`, (t) => {
let
tmp,
tmpFunc = () => { tmp = true; };
t.equal(windowMock._test, 'Window', 'should be a Window object');
t.equal(typeof windowMock.applicationCache, 'object', 'applicationCache should be an object');
t.equal(typeof windowMock.navigator, 'object', 'navigator should be an object');
t.equal(typeof windowMock.location, 'object', 'location should be an object');
t.equal(typeof windowMock.localStorage, 'object', 'localStorage should be an object');
t.equal(typeof windowMock.document, 'object', 'document should be an object');
t.equal(typeof windowMock.setTimeout, 'function', 'setTimeout should be a function');
tmp = false;
windowMock.setTimeout(tmpFunc);
t.equal(tmp, true, 'setTimeout should invoke callback');
t.equal(typeof windowMock.requestAnimationFrame, 'function', 'requestAnimationFrame should be a function');
tmp = false;
windowMock.requestAnimationFrame(tmpFunc);
t.equal(tmp, true, 'requestAnimationFrame should invoke callback');
t.equal(typeof windowMock.btoa, 'function', 'btoa should be a function');
t.equal(windowMock.btoa('x'), 'x', 'btoa should return');
t.end();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc