Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reducer-test-utils

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reducer-test-utils

![test status](https://travis-ci.com/christianheyn/reducer-test-utils.svg?branch=main "See the test status from travis-ci") [![npm version](https://badge.fury.io/js/reducer-test-utils.svg)](https://badge.fury.io/js/reducer-test-utils) ![ts](https://badgen

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Reducer-Test-Utils

test status npm version ts

Utilities for testing reducer functions

pipeActions

import { pipeActions } from "reducer-test-utils";

Chains multiple reducer actions and lets you test desired states. (Personally, I see it as a user journey that is treated as a reducer)

Usage:

import { pipeActions } from "reducer-test-utils";
import { myFeatureReducer, Action } from './myFeatureReducer'

describe("test my reducer function", () => {
  it("runs actions", () => {

    const userJourney = pipeActions(
      myFeatureReducer, // your reducer function
      { type: Action.ADD_1 } // actions and functions
      (state) => expect(state).toEqual(2),
      { type: Action.ADD_N, payload: 3 },
      { type: Action.ADD_1 },
      { type: Action.ADD_1 },
      (state) => expect(state).toEqual(7),
      { type: Action.SUB_2 },
      (state) => expect(state).toMatchSnapshot(),
    );

    const initialState = 1;

    userJourney(initialState);
    // userJourney(anotherInitialState);
  });
});

stateChanged

import { stateChanged, pipeActions } from "reducer-test-utils";

You can pass the return value of pipeActions and a initial state to stateChanged. All test functions are executed (exactly like pipeActions) plus a boolean value is returned, indicating whether the state has changed or not. (Deep equality test)

Usage:

import { stateChanged, pipeActions } from "reducer-test-utils";
import { myFeatureReducer, Action } from './myFeatureReducer'

describe("test my reducer function", () => {
  it("runs action", () => {

    const userJourney = pipeActions(
      myFeatureReducer,
      { type: Action.ADD_1 }
      (state) => expect(state).toEqual(2),
      { type: Action.ADD_N, payload: 3 },
      { type: Action.ADD_1 },
      { type: Action.ADD_1 },
      (state) => expect(state).toEqual(7),
    );

    const initialState = 1;
    const changed = stateChanged(userJourney, initialState);

    expect(changed).toBeTruthy();
  });
});

Keywords

FAQs

Package last updated on 07 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc