0.1.4 • Published 1 year ago

@smartesting/assert-contain-exactly v0.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@smartesting/assert-contain-exactly

Node.js CI

Simple test helper ensuring a list contains exactly the expected elements, without taking care of order. It is strongly inspired by Rspec's contain_exactly matcher.

Install

npm i --save-dev @smartesting/assert-contain-exactly

Usage

import assertContainExactly from "@smartesting/assert-contain-exactly";

const expected = ["a", "b", "c"];
const actual = getItems();
assertContainExactly(actual, expected);

When the arrays actual and expected, nothing happens. Otherwise, an exception is thrown and the message should help you spot the differences between the two arrays:

Error: Expected arrays to contain the same objects.
Missing elements were: [
  {
    id: "session-2",
    buildId: "13"
  }
]
Extra elements were: [
  {
    id: "session-B",
    buildId: "13"
  }
]
    at assertIncludesExactly (...)

Notes

This code is meant to be used for testing purposes. The algorithm is not that smart not designed to handle arrays with hundred of items.