New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

object-invariant-test-helper

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-invariant-test-helper

A module that is useful for testing whether you've mutated an object. Use it with [redux](http://redux.js.org/ 'redux.js.org') when testing your reducers to ensure you don't ever mutate an object in a reducer but always return a new object.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

object-invariant-test-helper

A module that is useful for testing whether you've mutated an object. Use it with redux when testing your reducers to ensure you don't ever mutate an object in a reducer but always return a new object.

This module began life as a fork of redux-immutable-state-invariant by Leonardo Andres Garcia Crespo (@leoasis).

Setup

This lib is intended for use only during development, specifically testing.

Don't use this in production!

npm install --save-dev object-invariant-test-helper

Usage

import objectInvariantTestHelper from '../src/index';

const toAdd = 2;
const expectedState = {num: 3};

describe('goodReducer', () => {
  it('should *not* mutate state', () => {
    let initialState = {num: 1};
    const tracked = objectInvariantTestHelper.trackObj(initialState);

    let finalState = goodReducer(initialState, {
      type: 'ADD',
      payload: { toAdd }
    });

    expect(finalState).toEqual(expectedState);
    expect(objectInvariantTestHelper.hasMutated(tracked)).toEqual(false);
  });
});

If you want to provide your own isImmutable function, you may:

import { objectInvariantTestHelperMkr } from '../src/index';
let objectInvariantTestHelper = objectInvariantTestHelperMkr(isImmutable);

FAQs

Package last updated on 12 Mar 2016

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