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

jazzdom

v1.2.0

Published

Promisified jsdom setup and teardown for your test runner.

Downloads

12

Readme

jazzdom

Build Status Coverage Status NPM

Promisified jsdom setup and teardown for your test runner.

Inspired from, and wraps, jsdom-global. Depends on jsdom.

Install

yarn add -D jazzdom jsdom jsdom-global

Setup

Option 1: Setting up and tearing down for tests that need a document object

import jazzdom from 'jazzdom'

describe('some tests', () => {
    before(() => jazzdom.create())
    after(() => jazzdom.destroy())
    // ... test content here
}

Option 2: Global setup line for test/mocha.opts

Don't do this if you plan to use the other setup option.

--require jazzdom/register

Example

In your mocha tests:

import React from 'react'
import { mount, shallow } from 'enzyme'
import jazzdom from 'jazzdom'

describe('Example', () => {
  const Parent = ({ children }) => <div className="parent">{children}</div>

  describe('without jazzdom integration', () => {
    it('shallow renders without need of jsdom', () => {
      const wrapper = shallow(
        <Parent><div className="child" /></Parent>
      )
      expect(wrapper.find('div.child')).to.exist
    })
  })

  describe('with basic integration', () => {
    before(() => jazzdom.create())
    after(() => jazzdom.destroy())

    it('mounts with the help of jsdom', () => {
      const wrapper = mount(
        <Parent><div className="child" /></Parent>
      )
      expect(wrapper.find('div.child')).to.exist
    })
  })

Best practices

  • If you trust your tests to clean up after themselves, you may wish to call require ('jazzdom/register') only once across your entire test suite, since that may result in speed improvements.
  • It can be good to separate fast and slow tests. "slow" tests would require jazzdom.create(), or other expensive tasks, and "fast" tests would not. Name them with slightly different patterns, and have two different test rules in package.json to call each suite. Prefer to have more fast tests and less slow tests. Instead of making multiple slow tests, consider making one slow test and spies for the remaining tests, if that makes sense for the situation.
  • Try to call jazzdom.create() and jazzdom.destroy() only when they're needed, such as with enzyme.mount(), and omit them with enzyme.shallow() and enzyme.render().
  • It's almost never a good idea to put jazzdom.create() and jazzdom.destroy() in a beforeEach() or afterEach() block. Prefer before() and after() blocks, or in dedicated it() blocks if your test runner doesn't support before/after.

Additional features compared to jsdom-global

  • Returns promises in separate create() and destroy() functions
  • Automatically routes console output from <script> tags into the standard node.js console object
  • Waits for jsdom created event to be fired before fulfilling or rejecting promise
  • If you forgot to destroy() the previous setup, the next create() call will throw an error that points to the previous invocation

License

MIT