window-mock
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"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(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21944
470
69
0