0.2.0 • Published 8 years ago

jasmine-collection-matchers v0.2.0

Weekly downloads
3,290
License
-
Repository
github
Last release
8 years ago

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.

0.2.0

8 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.10

9 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago