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

test-component-builder

v1.0.5

Published

A component builder used for testing. Mainly built for testing react components but is not limited to react.

Readme

Test Component Builder

A component builder used for testing. Mainly built for testing react components but is not limited to react.

To install run npm install test-component-builder

Example of using the component to build a simple Calendar component that accepts some properties.

import constructBuilder from "test-component-builder";

const builder = props => {
  //... some mocking
  /*return <Calendar {...props} />;*/
};

let calendarBuilder;
describe("test block description", () => {
  beforeEach(() => {
    calendarBuilder = constructBuilder(builder).with({
      /* some default props */
    });
  });

  it("test description", () => {
    const calendar = calendarBuilder
      .with({
        /*some specialized props*/
      })
      .using(/* some renderer, fx shallow from enzyme or react-testing-library */)
      .create(); /* <---- important, otherwise the resulting 
            object won't be created */

    /* ..asserts etc */
  });
});

If it is a requirement that the mocked components have parameters, this can be created using the inject method.

import constructBuilder from "test-component-builder";

const builder = props => deeperProps => {
  //... some mocking
  //... some mocking requireing parameters based on the test
  /*return <Calendar {...props} />;*/
};

let calendarBuilder;
describe("test block description", () => {
  beforeEach(() => {
    calendarBuilder = constructBuilder(builder).with({
      /* some default props */
    });
  });

  it("test description", () => {
    const calendar = calendarBuilder
      .with({
        /*some specialized props*/
      })
      .using(/* some renderer, fx shallow from enzyme or react-testing-library */)
      .inject(/* some props relative to this test */)
      .create(); /* <---- important, otherwise the resulting 
            object won't be created */

    /* ..asserts etc */
  });
});

The inject method works by injecting the props in the chained functions in order. for example inject(a).inject(b)... would inject like props => a => b =>.... inject also works as a step in the beforeEach method and any other method that is run before each test.

The only method that cannot be chained is the create method, this is the method that creates the final result of the builder, and must be run last.

Outline

| Method | Parameters | Description | | ----------------------------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | with(properties) | properties : object | Merges all the properties that are chained together with the with method. *These are merged with lodash assign. | | inject(values, clone) | values : objectclone : boolean default: true | Injects all the values that are chained together with the inject method in sequence. For example inject(a).inject(b)... would inject like props => a => b => .... values are cloned by default. | | override(key, values) | values : object | Searches for injected values that matches { key: key } and merges the passed in values with the values found. These are merged with lodash assign. If no key is found then this does nothing | | using(wrapper, prewrapper = null) | wrapper : function(result): result prewrapper : function(): void | Runs after both with and inject methods have been run on the whole chain. using accepts the result of the chain as an input; so chaining multiple using statements runs them in sequence, passing the previous wrapped result to the next chained wrapped. If a prewrapper is passed, it will be run before the wrapper and can be used fx. to make sure that the dom is cleared before rendering. | | create() | | Runs the chains that are created using the other methods in this order. with* -> inject* -> using* -> result. All other methods return the builder back, this returns the finished instance. |

These rendereres are recommended when using test-component-builder for testing react components.

  1. react-testing-library by Kent C. Dodds
  2. Enzyme by Airbnb