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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-emmet-assertion

v1.1.1

Published

Provides structural assertions for React components using Emmet templates

Downloads

47

Readme

react-emmet-assertion

Description

This library exists to make the testing of structural output from React simple. Most approaches to structural tests tend to require the use of shallow-rendering frameworks and indirect behavioral testing through simulated events. This library attempts to offer a less involved process for testing output from React components.

Before you begin

Due to the way Emmet works out-of-the-box, some abbreviations implicitly provide placeholder attributes (e.g. a resolves to <a href="">). As this behavior makes it difficult to test-drive DOM creation without having all of the relevant details up-front, the react-emmet-assertion library makes some adjustments to Emmet's defaults:

  • a is rewritten from <a href=""> to <a>
  • img is rewritten from <img src="" alt="" /> to <img />
  • form is rewritten from <form action=""> to <form>
  • input is rewritten from <input type="text" /> to <input />

As the above changes affect the Emmet library as a whole, consuming this assertion library in a project that already utilizes Emmet may have unintended side-effects. This fact is documented as an issue.

Usage

This library directly tests the JSX component tree from a component's .render() method (or the direct output from pure functional components). The emmetAssert function wraps this output and permits emmet expressions to be evaluated against it:

import emmetAssert from 'react-emmet-assertion';

const FunctionalThing = (props) => <div className={props.className}>{props.caption}</div>;
const renderedComponent = FunctionalThing({className: 'test', caption: 'Hello'});

const wrapped = emmetAssert(renderedComponent);

From there, it is possible to perform assertions or to query for a specific node:

Tests (.includes)

To assert that the wrapped component matches the provided Emmet path:

const emmetPath = 'div.test{Hello}';

wrapped.includes(emmetPath); // should not throw an error, perfect match
wrapped.includes('div'); // also should not throw an error, inclusive match
wrapped.includes('span'); // throws "Error: (at [0]) expected node span, found div"
wrapped.includes('div>span'); // throws "Error: (at [0],[0]) expected node span, found undefined"

Error output from .includes failures attempt to specify the location of the failure, to better facilitate diagnosis of failures or for TDD that is driven by error output. The format of this message is given as:

Error: (at <path>) <reason>

...where <path> is a comma-delimited series of zero-indexed identifiers that describe the node under test, and <reason> is an explanation of which test failed.

Queries (.find)

The wrapped object also exposes a .find method that, like .includes, accepts an emmet path. Instead of performing an assertion, though, the utility will return the last matching React element. The intent of this is that developers may wish for opportunity to perform tests against nodes that are not satisfactorily provided by the emmet assertions (e.g. testing the qualities of props passed to child components).

const element = <section className="main">
    <ul>
        <li>
            <label>
                <span>1</span>
                <input type="checkbox" name="items[]" value="1" />
            </label>
        </li>
        <li>
            <label>
                <span>2</span>
                <input type="checkbox" name="items[]" value="2" />
            </label>
        </li>
        <li>
            <label>
                <span></span>
                <input type="checkbox" name="items[]" value="1" />
            </label>
        </li>
        <li>
            <label>
                <span></span>
                <input type="checkbox" name="items[]" value="1" />
            </label>
        </li>
        <li>
            <label>
                <span></span>
                <input type="checkbox" name="items[]" value="1" />
            </label>
        </li>
    </ul>
</section>;

const wrapped = emmetAssert(element);
const spanWithTwo = wrapped.find('section>ul>li*2>label>span');  // should return <span>2</span>