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

jest-immutable-matchers

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-immutable-matchers

Add a set of custom matchers for Immutable related checks.

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

jest-immutable-matchers Version

List of matchers

  • toBeImmutable
  • toBeIterableImmutable
  • toBeKeyedImmutable
  • toBeIndexedImmutable
  • toBeAssociativeImmutable
  • toBeOrderedImmutable
  • toBeImmutableList
  • toBeImmutableMap
  • toBeImmutableOrderedMap
  • toBeImmutableSet
  • toBeImmutableOrderedSet
  • toBeImmutableStack
  • toBeImmutableSeq
  • toEqualImmutable

Installation

Just run:

$ npm install --save-dev jest-immutable-matchers

Usage

Load these matchers in a beforeEach block, and then use them like any other matcher:

expect(Immutable.Map()).toBeImmutable()

TypeScript

This package includes the necessary declarations for TypeScript. Just make sure they get loaded in your project, for example by adding the package name to the types field in your tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jest",
      "jest-immutable-matchers"
    ]
  }
}

Then just load the matchers at runtime in your tests:

import * as matchers from 'jest-immutable-matchers';

describe('My suite', function () {
  beforeEach(function () {
    expect.extend(matchers);
  });

  it('passes if the object is immutable', function () {
    expect(Immutable.Map()).toBeImmutable();
  });

  it('passes if the immutable objects are equal', function () {
    expect(Immutable.Map({a: 1})).toEqualImmutable(Immutable.Map({a: 1}));
  });
});

ES2015

If you are using the new module syntax, import all exported matchers:

import * as matchers from 'jest-immutable-matchers';

describe('My suite', function () {
  beforeEach(function () {
    expect.extend(matchers);
  });

  it('passes if the object is immutable', function () {
    expect(Immutable.Map()).toBeImmutable();
  });

  it('passes if the immutable objects are equal', function () {
    expect(Immutable.Map({a: 1})).toEqualImmutable(Immutable.Map({a: 1}));
  });
});

Note that jest-immutable-matchers does not have a default export!

AMD/CommonJS

If you are using AMD or CommonJS, require normally:

var matchers = require('jest-immutable-matchers');

describe('My suite', function () {
  beforeEach(function () {
    expect.extend(matchers);
  });

  it('passes if the object is immutable', function () {
    expect(Immutable.Map()).toBeImmutable();
  });

  it('passes if the immutable objects are equal', function () {
    expect(Immutable.Map({a: 1})).toEqualImmutable(Immutable.Map({a: 1}));
  });
});

Global

Otherwise, use window['jest-immutable-matchers']:

var matchers = window['jest-immutable-matchers'];

describe('My suite', function () {
  beforeEach(function () {
    expect.extend(matchers);
  });

  it('passes if the object is immutable', function () {
    expect(Immutable.Map()).toBeImmutable();
  });

  it('passes if the immutable objects are equal', function () {
    expect(Immutable.Map({a: 1})).toEqualImmutable(Immutable.Map({a: 1}));
  });
});

Keywords

FAQs

Package last updated on 17 Jul 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