Skip to content

Commit

Permalink
Merge pull request #213 from Short-cm/master
Browse files Browse the repository at this point in the history
.equal now checks for isImmutable instead of isIterable
  • Loading branch information
astorije authored Apr 21, 2019
2 parents b0fcdae + 939a6db commit afad864
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ os:
- linux
- osx

matrix:
include:
- env: IMMUTABLE_VERSION=^4.0.0-rc

install:
- yarn install --frozen-lockfile

before_script:
- if [ "$IMMUTABLE_VERSION" ]; then yarn add --dev immutable@$IMMUTABLE_VERSION; fi

after_script:
- if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_NODE_VERSION" == "11" ]]; then yarn coveralls; fi

Expand Down
22 changes: 15 additions & 7 deletions chai-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
context.chai.use(factory(context.Immutable));
}
})(this, Immutable => (chai, utils) => {
function isImmutable(value) {
if (typeof Immutable.isImmutable === 'undefined') {
return Immutable.Iterable.isIterable(value);
} else {
return Immutable.isImmutable(value);
}
}

const { Assertion } = chai;

function assertIsIterable(obj) {
Expand Down Expand Up @@ -95,11 +103,11 @@
* @api public
*/

function assertCollectionEqual(_super) {
function assertImmutableEqual(_super) {
return function(collection) {
const obj = this._obj;

if (Immutable.Iterable.isIterable(obj)) {
if (isImmutable(obj)) {
this.assert(
Immutable.is(obj, collection),
'expected #{act} to equal #{exp}',
Expand All @@ -114,11 +122,11 @@
};
}

Assertion.overwriteMethod('equal', assertCollectionEqual);
Assertion.overwriteMethod('equals', assertCollectionEqual);
Assertion.overwriteMethod('eq', assertCollectionEqual);
Assertion.overwriteMethod('eql', assertCollectionEqual);
Assertion.overwriteMethod('eqls', assertCollectionEqual);
Assertion.overwriteMethod('equal', assertImmutableEqual);
Assertion.overwriteMethod('equals', assertImmutableEqual);
Assertion.overwriteMethod('eq', assertImmutableEqual);
Assertion.overwriteMethod('eql', assertImmutableEqual);
Assertion.overwriteMethod('eqls', assertImmutableEqual);

/**
* ### .include(value)
Expand Down

0 comments on commit afad864

Please sign in to comment.