New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jsdomify

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsdomify

Create a JSDom instance for browserless testing, exposing some handling methods

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
decreased by-16.57%
Maintainers
1
Weekly downloads
 
Created
Source

jsdomify

A ready to use DOM right at your finger tips for easy and fast testing without any browser in the Node environment (with mocha, for example)

Getting started

npm install jsdomify

Usage

You can create a new jsdom instance simply with

var jsdomify = require('jsdomify').create()

Or you can provide a valid HTML string that will be used as your DOM

var jsdomify = require('jsdomify').create('<!DOCTYPE html><html><head></head><body>hello</body></html>')

Methods

jsdomify expose some useful methods that can be used to control the DOM instance

create(domString)

jsdomify.create()

Create a new DOM instance (with or withouth the optional DOM string).

clear()

jsdomify.clear()

Clear the current instance and recreate a new one using the same DOM string (basically clearing up the DOM).

destroy()

jsdomify.destroy([clearRequireCache])

Close the window and destroy the document. Can be used to isolate the tests and prevent leaking from one test suite to another.

If clearRequireCache === true all the cached node require modules will be purged (defaults to true).
This is needed in order to use ReactJS with MochaJS.

Related issues:

Usage examples

From our very own test suite

describe('Isolation test', function() {

  before(function() {
    jsdomify.create();
  });

  beforeEach(function() {
    jsdomify.clear();
  });

  after(function() {
    jsdomify.destroy();
  });

  it('should append a child to the body', function() {

    var par = document.createElement("P");
    var text = document.createTextNode("some text");
    par.appendChild(text);
    document.body.appendChild(par);
    var parCount = document.getElementsByTagName("P");

    expect(document.body.innerHTML, 'not to be empty');
    expect(parCount.length, 'to be', 1);
  });

  it('should not find the previously appended child', function() {

    var parCount = document.getElementsByTagName("P");

    expect(document.body.innerHTML, 'to be empty');
    expect(parCount.length, 'to be', 0);
  });

});

Test

npm test

License

MIT

Keywords

FAQs

Package last updated on 15 Jul 2015

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