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

jest-element-snapshots

v2.1.0

Published

Test against snapshots of DOM elements

Downloads

10

Readme

jest-element-snapshots

Make capturing & comparing snapshots of the puppeteer DOM easier!

Installing

  1. npm install jest-element-snapshots --save-dev
  2. Add this snippet somewhere in your tests (a setupTestFrameworkScriptFile is a good place)
require("jest-element-snapshots")();

This will install the .toMatchDOMSnapshot() functionality onto .expect(). See the Installation API section for available options.

Usage

it("should generate some consistent output", async () => {
    await page.goto("http://example.com");

    // Will look up the element in puppeteer,
    // grab its .outerHTML value,
    // and compare it against any previous snapshot value
    //
    // This is an **async** matcher so use await!
    await expect("body").toMatchDOMSnapshot();
});

API

Installation API

jest-element-snapshots exports a function that will take one optional arg, an object of configuration params.

All params are optional.

Params

page

A reference to the puppeteer page object. If you're using jest-puppeteer the default will work fine.

waitFor

If truthy will make the matcher wait for the selector to exist in the DOM before attempting to read the element from the DOM. If falsey the matcher will attempt to read the element from the DOM immediately.

Usage API

expect(<string|ElementHandle> element).toMatchDOMSnapshot(<string> hint, <object> options)

Arguments

element

Either a string CSS selector, or a puppeteer ElementHandle. Will be used to locate the element in the DOM to snapshot.

hint

A string that is passed to the underlying jest .toMatchSnapshot() code as the hint parameter to give snapshots an extra name, useful for differentiating multiple snapshots in a single test.

options

Snapshot-specific options, will override any options set globally.

waitFor

If truthy will make the matcher wait for the selector to exist in the DOM before attempting to read the element from the DOM. If falsey the matcher will attempt to read the element from the DOM immediately.