Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

jsdom-global

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jsdom-global

Enable DOM in Node.js


Version published
Weekly downloads
428K
increased by4.89%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

[v1.3.0]

Jan 11, 2016

  • Add browserify support.

Readme

Source

jsdom-global

Enables DOM in Node.js

jsdom-global will inject document, window and other DOM API into your Node.js environment. Useful for tests.

Status

Install

Requires jsdom.

npm install --save-dev --save-exact jsdom jsdom-global

Usage

Just invoke it to turn your Node.js environment into a DOM environment.

var jsdom = require('jsdom-global')
jsdom()

// you can now use the DOM
document.body.innerHTML = 'hello'

To clean up after itself, just invoke the function it returns.

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.

jsdom(function () {
  var $ = require('jquery')
  $('body').html('hello')
})

Tape

In tape, run it before your other tests.

var test = require('tape')

// example: run your tests with `env JSDOM=1` to enable jsdom in an otherwise
// browser-only test
if (process.env.JSDOM) {
  test('jsdom', (t) => {
    require('jsdom-global')()
    t.pass('jsdom enabled')
    t.end()
  })
}

Or even use the tape helper, which will accomplish the same thing:

var test = require('tape')
test('jsdom', require('jsdom-global/tape')())

Mocha

Just add it to mocha's before and after hooks.

before(function () {
  this.jsdom = require('jsdom-global')()
})

after(function () {
  this.jsdom()
})

Thanks

jsdom-global © 2016+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz

Keywords

FAQs

Last updated on 11 Jan 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc