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

htmlassertjs

v0.0.9

Published

A fluent HTML testing api to assert HTML path and content

Readme

HtmlAssertjs

HtmlAssertjs is a Javascript DSL based assertion API to assert HTML path and content.

Huh? What?

Let's imagine you have some HTML content

<div id="someId">
  <p class="someClass">
     <span>text</span>
  </p>
</div>

And you have a (javascript) test that needs to verify that you actually have :

  • a <div> tag with an id attribute having the "someId" value.
  • inside this <div>, a <p> tag with a class attribute having the "someClass" value.
  • inside this <p>, a <span> tag.

HtmlAssertjs is the answer to this problem by providing an easy API that will let you write such assertions.

HtmlAssertjs uses a DSL based interface, using methods chaining, in order to allow to write tests that are as explicit as possible. Testing the above HTML code would be done like this :

htmlassert.that("it tests a passing div", htmlToTest.contains.div("id", "someid").p("class","someClass").span());

Quickstart

  1. Include the library in your project:

    npm install htmlassertjs --save-dep

  2. This is how we write a simple test:

    var htmlassert = require("htmlassertjs");

    var html = "<div class="someclass" id="someid">";

    var htmlToTest = htmlassert.containing(html); htmlassert.that("it tests some basic HTML", htmlToTest.contains.p().div("id", "someid", "class", "someclass") );

  3. You do two main steps : providing the HTML, then calling the assertions

    var htmlToTest = htmlassert.containing(html);

by calling the containing(html) method, you create an object that contains the HTML.

then you can call the assertions on this object, by calling the that method

htmlassert.that("it tests some assertion", 
                 htmlToTest.contains.p().div().span()
               );

At this point, you can call several assertions on the same html object, e.g.:

var htmlToTest = htmlassert.containing(html);

htmlassert.that("it tests some assertion number 1", 
                 htmlToTest.contains.p().div().span()
               );
htmlassert.that("it tests some assertion number 2", 
                 htmlToTest.contains.p().span()
               );
  1. By default, the assertion is lenient, it means that if you do not need to include all tags in your assertion:

    var htmlassert = require("htmlassertjs");

    var html = "<div class="someclass">";

    var htmlToTest = htmlassert.containing(html); htmlassert.that("it tests some basic HTML", htmlToTest.contains.p().div("id", "someid", "class", "someclass").span() ); htmlassert.that("it tests some basic HTML leniently", htmlToTest.contains.p().span() );

both of those assertions will work, even the second where you did not indicated the <div> tag.

Note : A strict mode will be implemented

  1. Testing the attributes of a tag is sometimes heavy, so you can use a wildcard

    var html = "<div style="font-size: 150%; color: red;">"; htmlassert.that("it tests some attributes with a wildcard", htmlToTest.contains.div("style", "font-size:color:") );

Problems?

I'm not an expert in Javascript, so if you have any feedback, you're welcome to do it, please raise a issue on github : HtmlAssertjs issues and comments

Contributing

The tests are included in the test directory and are using casperjs.

  • You need casperjs v1.1.x installed (globally)
  • then install the node modules : npm install
  • then execute the tests : grunt test

The code is in the lib directory