jest-array-equal
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

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

/jest-array-equal/

    Package Sidebar

    Install

    npm i jest-array-equal

    Weekly Downloads

    55

    Version

    0.0.2

    License

    none

    Unpacked Size

    17.5 kB

    Total Files

    11

    Last publish

    Collaborators

    • jgillick