Skip to content

Commit

Permalink
Assert that objects are iterable instead of instances of Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelazaroff committed Dec 15, 2015
1 parent 047f61b commit 38d485d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions chai-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@

var Assertion = chai.Assertion;

function assertIsIterable(obj) {
new Assertion(obj).assert(
Immutable.Iterable.isIterable(obj),
'expected #{this} to be an Iterable'
);
}

/**
* ## BDD API Reference
*/
Expand Down Expand Up @@ -309,7 +316,7 @@
*/

function assertCollectionSize(n) {
new Assertion(this._obj).instanceof(Collection);
assertIsIterable(this._obj);

var size = this._obj.size;
new Assertion(size).a('number');
Expand All @@ -335,7 +342,7 @@
function assertCollectionSizeLeast(_super) {
return function (n) {
if (utils.flag(this, 'immutable.collection.size')) {
new Assertion(this._obj).instanceof(Collection);
assertIsIterable(this._obj);

var size = this._obj.size;
new Assertion(size).a('number');
Expand All @@ -355,7 +362,7 @@
function assertCollectionSizeMost(_super) {
return function (n) {
if (utils.flag(this, 'immutable.collection.size')) {
new Assertion(this._obj).instanceof(Collection);
assertIsIterable(this._obj);

var size = this._obj.size;
new Assertion(size).a('number');
Expand All @@ -375,7 +382,7 @@
function assertCollectionSizeAbove(_super) {
return function (n) {
if (utils.flag(this, 'immutable.collection.size')) {
new Assertion(this._obj).instanceof(Collection);
assertIsIterable(this._obj);

var size = this._obj.size;
new Assertion(size).a('number');
Expand All @@ -395,7 +402,7 @@
function assertCollectionSizeBelow(_super) {
return function (n) {
if (utils.flag(this, 'immutable.collection.size')) {
new Assertion(this._obj).instanceof(Collection);
assertIsIterable(this._obj);

var size = this._obj.size;
new Assertion(size).a('number');
Expand Down Expand Up @@ -429,7 +436,7 @@
Assertion.overwriteMethod('within', function (_super) {
return function (min, max) {
if (utils.flag(this, 'immutable.collection.size')) {
new Assertion(this._obj).instanceof(Collection);
assertIsIterable(this._obj);

var size = this._obj.size;
new Assertion(size).a('number');
Expand Down

0 comments on commit 38d485d

Please sign in to comment.