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

@malfaitrobin/redux-test-utils

v0.0.1

Published

Redux utilities

Readme

Test Utilities

testReducer

NOTE: This example uses Jest. We also use a feature called snapshot testing.

Standard example:

import { testReducer } from "@malfaitrobin/redux-test-utils";

import reducer from "./reducer";
import * as actionCreators from "./actionCreators";

const calculator = testReducer(reducer);

describe("calculator", () => {
  it("should be able to calculate the universe", () => {
    const actions = [
      actionCreators.add(20),
      actionCreators.multiply(3),
      actionCreators.subtract(18)
    ];

    expect(calculator(actions)).toMatchSnapshot();
  });
});

The result of the snapshot will have the initial state Followed by the action followed by the state and so on. The snapshot will eventually look something like this:

Array [
  State {
    "value": 0,
  },
  Action {
    "payload": 20,
    "type": "ADD",
  },
  State {
    "value": 20,
  },
  Action {
    "payload": 3,
    "type": "MULTIPLY",
  },
  State {
    "value": 60,
  },
  Action {
    "payload": 18,
    "type": "SUBTRACT",
  },
  State {
    "value": 42,
  },
]

Overriding the current state before testing

Let's say that the default state from the reducer looks like { value: 0 }, but now you want to test the multiply function. Since multiplying by 0 is a no-op, we can override the "initial" value.

import { testReducer } from "@malfaitrobin/redux-test-utils";

import reducer from "./reducer";
import * as actionCreators from "./actionCreators";

const calculator = testReducer(reducer);

describe("calculator", () => {
  it("should be able to calculate the universe", () => {
    const actions = [actionCreators.multiply(3)];

    expect(
      calculator(actions, {
        value: 14
      })
    ).toMatchSnapshot();
  });
});

Normally the snapshot would have looked like this:

Array [
  State {
    "value": 0,
  },
  Action {
    "payload": 3,
    "type": "MULTIPLY",
  },
  State {
    "value": 0,
  },
]

But since we provided a default "initial" value, the snapshot looks like this:

Array [
  State {
    "value": 14,
  },
  Action {
    "payload": 3,
    "type": "MULTIPLY",
  },
  State {
    "value": 42,
  },
]

Using testReducer to also test the selectors

  • A reducer always operates on its part of the state
  • A selector retrieves information from the full state in the application
// selectors.js

export function getCurrentValue(state) {
  return state.applications.calculator.value;
}
import { testReducer } from "@malfaitrobin/redux-test-utils";

import reducer from "./reducer";
import * as actionCreators from "./actionCreators";
import * as selectors from "./selectors";

// We can mimic the "full" state, which will be used by selectors
const calculator = testReducer(reducer, state => {
  return {
    applications: {
      calculator: state
    }
  };
});

describe("calculator", () => {
  it("should be to retrieve the current value", () => {
    const actions = [
      actionCreators.add(20),
      actionCreators.multiply(3),
      actionCreators.subtract(18)
    ];

    // A final `state` object can be retrieved from the reducer
    const { state } = calculator(actions);

    // Now the selector can operate on the "full state"
    expect(selectors.getCurrentValue(state)).toMatchSnapshot();
  });
});