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

jsdom-global

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

jsdom-global

Enable DOM in Node.js

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
493K
increased by1.1%
Maintainers
1
Weekly downloads
 
Created

What is jsdom-global?

The jsdom-global npm package is used to set up a global DOM environment in Node.js, which is particularly useful for testing and running scripts that are designed to work in a browser environment. It leverages the jsdom library to create a simulated DOM, allowing developers to run browser-specific code in a Node.js environment.

What are jsdom-global's main functionalities?

Global DOM Setup

This feature sets up a global DOM environment by requiring the jsdom-global package. The code sample demonstrates how to initialize the global DOM and log the document object to the console.

require('jsdom-global')();
console.log(window.document);

Simulating Browser APIs

This feature allows you to simulate browser-specific APIs like `alert`. The code sample shows how to override the `alert` function to log messages to the console instead.

require('jsdom-global')();
window.alert = (msg) => console.log(`Alert: ${msg}`);
window.alert('Hello, world!');

Testing with Mocha

This feature is useful for setting up a DOM environment for testing purposes. The code sample demonstrates how to use jsdom-global with the Mocha testing framework and Chai assertion library to test DOM manipulation.

const jsdomGlobal = require('jsdom-global');
const { expect } = require('chai');

jsdomGlobal();
describe('DOM Manipulation', () => {
  it('should create a new div element', () => {
    const div = document.createElement('div');
    document.body.appendChild(div);
    expect(document.body.contains(div)).to.be.true;
  });
});

Other packages similar to jsdom-global

Keywords

FAQs

Package last updated on 11 Jan 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc