jasmine-collection-matchers

0.2.0 • Public • Published

jasmine-collection-matchers Build Status

A set matchers which helps compare collections

If you are using standard jasmine toEqual when comparing arrays, you may get the following error:

Message:
  Expected [ 1, 2, 3, 4, 5, 6 ] to equal [ 1, 2, 3, 4, 4, 6 ].

It can be hard to notice that fifth element is wrong. This module adds new matchers specially for collections that will print more detailed error messages about the values differences.

Message:
  The collections have equal length, but do not match.
    At 4: expected 5, actual 4

Much clearer!

Usage:

Node JS:

Install via npm:

npm install jasmine-collection-matchers

Require into your tests and use:

require('jasmine-collection-matchers')
 
it('should match collection', function() {
    expect([1,2]).toHaveSameItems([1,2])
});

Browser

Include combined matchers file:

<script src="/node_modules/jasmine-collection-matchers/lib/pack.js"></script>

Now you can use new matchers

it('should match collection', function() {
    expect([1,2]).toHaveSameItems([1,2])
});

Matchers

expect(<Array, Object>).toHaveSameItems(<Array, Object>, [<boolean> ignoreSort])

Validates that passed arrays or objects are identical. If not, prints the difference.

ignoreSort — ignore items order while comparing arrays. Default to false.

expect(<Array>).toHaveUniqueItems()

Validates that all items in array are unique. If not, prints indexes of duplicates

expect(<Array, String>).toHaveLength(<Number>)

Throws if actual does not have a length property

Validates the length vs. the expectation.

Package Sidebar

Install

npm i jasmine-collection-matchers

Weekly Downloads

654

Version

0.2.0

License

none

Last publish

Collaborators

  • just-boris