Skip to content

Commit

Permalink
Add support for assert.sizeOf (relates to #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
astorije committed Mar 15, 2015
1 parent 3e5c90b commit 9e5aa57
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,15 @@ var a = List.of(1, 2, 3);
var b = List.of(1, 2, 3);
assert.equal(a, b);
```

### .sizeOf(collection, length)

- **@param** *{Collection}* collection
- **@param** *{Number}* size

Asserts that the immutable collection has the expected size.

```js
assert.sizeOf(List.of(1, 2, 3), 3);
assert.sizeOf(new List(), 0);
```
20 changes: 20 additions & 0 deletions chai-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,24 @@ module.exports = function (chai, utils) {
}
else return assert.equal;
};

/**
* ### .sizeOf(collection, length)
*
* Asserts that the immutable collection has the expected size.
*
* ```js
* assert.sizeOf(List.of(1, 2, 3), 3);
* assert.sizeOf(new List(), 0);
* ```
*
* @name sizeOf
* @param {Collection} collection
* @param {Number} size
* @api public
*/

assert.sizeOf = function (collection, expected) {
new Assertion(collection).size(expected);
};
};
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,15 @@ describe('chai-immutable', function () {
assert.notDeepEqual(list3, new List());
});
});

describe('sizeOf assertion', function () {
it('should be true when given the right size', function () {
assert.sizeOf(List.of(1, 2, 3), 3);
});

it('should work with empty collections', function () {
assert.sizeOf(new List(), 0);
});
});
});
});

0 comments on commit 9e5aa57

Please sign in to comment.