jsdom-global
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -0,1 +1,8 @@ | ||
## [v1.1.0] | ||
> Jan 11, 2016 | ||
- Add `cleanup()`. | ||
[v1.1.0]: https://github.com/rstacruz/jsdom-global/compare/v1.0.0...v1.1.0 | ||
## [v1.0.0] | ||
@@ -2,0 +9,0 @@ > Jan 11, 2016 |
11
index.js
@@ -8,6 +8,6 @@ /* | ||
try { | ||
var keys = globalize() | ||
var cleanup = globalize() | ||
return func() | ||
} finally { | ||
keys.forEach(function (key) { delete global[key] }) | ||
cleanup() | ||
} | ||
@@ -43,3 +43,8 @@ } else { | ||
window.console = global.console | ||
return keys | ||
function cleanup () { | ||
keys.forEach(function (key) { delete global[key] }) | ||
} | ||
return cleanup | ||
} |
{ | ||
"name": "jsdom-global", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Enable DOM in Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -31,2 +31,13 @@ # jsdom-global | ||
To clean up after itself, just invoke the function it returns. | ||
```js | ||
var jsdom = require('jsdom-global') | ||
var cleanup = jsdom() | ||
// do things | ||
cleanup() | ||
``` | ||
You can also invoke it with a function block so it'll clean up afterwards. | ||
@@ -41,2 +52,4 @@ | ||
## Tape | ||
In [tape][], run it before your other tests. | ||
@@ -65,4 +78,18 @@ | ||
## Mocha | ||
Just add it to [mocha]'s `before` and `after` hooks. | ||
```js | ||
before(function () { | ||
this.jsdom = require('jsdom-global')() | ||
}) | ||
after(function () { | ||
this.jsdom() | ||
}) | ||
``` | ||
[tape]: https://github.com/substack/tape | ||
[mocha]: https://mochajs.org/ | ||
@@ -69,0 +96,0 @@ ## Thanks |
13
test.js
var test = require('tape') | ||
var jsdom | ||
test('jsdom', require('./tape')()) | ||
test('jsdom', function (t) { | ||
jsdom = require('./index')() | ||
t.end() | ||
}) | ||
@@ -12,1 +16,8 @@ test('dom', function (t) { | ||
}) | ||
test('cleanup', function (t) { | ||
jsdom() | ||
t.ok(typeof global.document === 'undefined', 'cleaned document') | ||
t.ok(typeof global.alert === 'undefined', 'cleaned alert') | ||
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
4881
69
104