Skip to content

Provides array equality matchers for jest.

License

Notifications You must be signed in to change notification settings

bugi14/jest-array-equal

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Provides array equality matchers for jest.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 96.5%
  • JavaScript 3.5%