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

html-fixture

v0.9.15

Published

A small JS library to create html test fixtures in an easy way

Readme

html-fixture

A small JS library to create html test fixtures in an easy way

A quick example:

  const HtmlFixture=require('html-fixture');  //or import

  const htmlFixture=new HtmlFixture();
  htmlFixture.create();
  htmlFixture.append("<p>1</p>");
  htmlFixture.append("<a>2</a><p>3</p>");
  

  const allDomElementsP=htmlFixture.elementsByTag("p");
  const onlyfirstP=htmlFixture.elementBySelector("p:first-child");

  htmlFixture.destroy();

This package exposes a class to manipulate and query an htmlFixture, the intended use is in testing

All methods:

create()

Creates a div in DOM to hold all the rest of the html fixture (you append html with the append method) All the content in the fixture is always inside this DOM. You can get this DOMElement with the ``rootElement``` method.

If you execute create() twice without calling destroy()`` on the the same instance if automatically calls destroy```

The div element created is invisible ("display:none") and contains an attribute id="html-fixture-"+GUID

destroy()

Removes the div in DOM inserted by create()

append(string|DOMElement|function)

appends the html in the param to the fixture.

append accepts either an string with the html:

  htmlFixture.append("<a href='http://example.com'>Example</a>");  

a DOMElement:

    const domElement=document.createElement("span");
    htmlFixture.append(domElement);

a function with a comment and the html inside the comment:

    var INITIAL_HTML=function(){/*
         <img src="images/test1.jpg">
         <p>Sample Text</p>
     */};
     
    htmlFixture.append(INITIAL_HTML);

This feature exists to simplify insertion of complex Html if you use Ecmascript 5

isEmpty()

returns true if the content of the fixture is empty

asString()

returns the content of the fixture as a string (without the containing div, only the content that was added on ```append```)

isEqual(string|DOMElement|function)

 this method accepts the same types of param as ```append```.
 Compares the content of the fixture and the param and return true if it considers that are equal
 
 * ignores multiples spaces & case
 * respects the comments in html
 * transform entities to unicode when possible
 
 Some examples:
 
     const domElement=document.createElement("span");
     htmlFixture.append("<span></span>");
     htmlFixture.isEqual(domElement); //true
 
     const htmlLowerCase="<div><p></p></div><img/>";
     const htmlUpperCase="<DIV><P></P></DIV><IMG/>";
     htmlFixture.append(htmlLowerCase);
     htmlFixture.isEqual(htmlUpperCase); //true
 
     const html="<div><p></p></div><img/>";
     const htmlWithSpaces="   <div>   <p>    </p>    </div>    <img/>      ";
     htmlFixture.append(html);
     htmlFixture.isEqual(htmlWithSpaces); //true
 
     const htmlWithAttribInLowercase="<div id='id'><p></p></div><img/>";
     const htmlWithAttribInUppercase="<div ID='id'><p></p></div><img/>";
     htmlFixture.append(htmlWithAttribInUppercase);
     htmlFixture.isEqual(htmlWithAttribInLowercase); //true
 
     const html="<div><p> A text </p> Another text</div><img>";
     htmlFixture.append(html);
     htmlFixture.isEqual(html); //true
 
     const html="<div><!-- a comment --></div>";
     htmlFixture.append(html);
     htmlFixture.isEqual(html); //true
 
     const html="<p>Acci&oacute;n</p>";
     htmlFixture.append(html);
     htmlFixture.isEqual("<p>Acción</p>"); //true
      
 ```
 

elementByTag(tagName)

returns the first element in the fixture that has the specified tag name
    const html="<p>1</p><a>2</a><p>3</p>";
    htmlFixture.append(html);
    htmlFixture.elementByTag("p");// returns the DOMElement that refers to "<p>1</p>"

elementBySelector(selector)

returns the first element in the fixture that has matches the specified selector

```selector``` as per [w3c](https://www.w3.org/TR/selectors-3)
    const html="<p>1</p><a>2</a><p>3</p>";
    htmlFixture.append(html);
    htmlFixture.elementBySelector("p:first-child"); // returns the DOMElement that refers to "<p>1</p>"

elementsByTag(tagName) && elementsBySelector(selector)

Same as elementByTag(tagName) && ``elementBySelector(selector)``` but returns an array with all the elements in the fixture instead of only the first element.

Some examples:

    const html="<p>1</p><a>2</a><p>3</p>";
    fixture.append(html);
    const elements = fixture.elementsByTag("p");
    elements[0].outerHTML; // "<p>1</p>"
    elements[1].outerHTML; // "<p>3</p>"


    const html="<p class="title">1</p><a class="title">2</a><p>3</p>";
    fixture.append(html);
    const elements = fixture.elementsBySelector(".title");
    elements[0].outerHTML; // "<p class="title">1</p>"
    elements[1].outerHTML; // "<a class="title">2</a>"