npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsdomify-compat

v1.0.0

Published

Create a JSDom instance for browserless testing (node 0.1x compatible)

Downloads

3

Readme

jsdomify-compat

Build Status Coverage Status

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

This is the compatibility version of jsdomify which can run in node.js version 0.10 and 0.12, using JSDOM version 3.1.2

Getting started

npm install --save-dev jsdomify-compat

Usage

You can create a new jsdom instance simply with

var jsdomify = require('jsdomify-compat').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 without 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:

getDocument()

var documentRef = jsdomify.getDocument();
var elm = documentRef.getElementById('whatever');

Get a reference to the document that has been created as a global.
Useful when running with strict linting that doesn't allow globals but still want to test things on the document itself.

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