Socket
Socket
Sign inDemoInstall

jest-array-equal

Package Overview
Dependencies
1
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest-array-equal

A couple straightforward jest array equality matchers.


Version published
Maintainers
1
Install size
63.8 MB
Created

Readme

Source

Jest Array Equal Matchers

A couple straightforward jest array equality matchers.

expect([1, 2, 4]).toEqualArray([2, 4, 1]); // Pass
expect([1, 2, 4, 5]).toEqualArray([2, 4, 1]); // Fail

Install

npm

npm install -D jest-array-equal

Yarn

npm add -D jest-array-equal

In any test file, or the global jest setup file:

import { arrayMatchers } from 'jest-array-equal';
expect.extend(arrayMatchers);

Usage

The matcher will be true if the arrays have the exact same contents, regardless of order.

expect([1, 2, 4]).toEqualArray([2, 4, 1]); // Pass
expect([1, 2, 4, 5]).toEqualArray([2, 4, 1]); // Fail
expect([1, 2, 4]).toEqualArray([2, 4, 1, 1]); // Fail

Array of objects

If you want to match arrays of objects by a particular property value:

expect([{ id: 1, id: 2 }]).toEqualArrayBy('id', [{ id: 2, id: 1 }]); // Pass
expect([{ id: 1, id: 2 }]).toEqualArrayBy('id', [{ id: 1, id: 3 }]); // Fail

FAQs

Last updated on 02 Mar 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc