diff --git a/.travis.yml b/.travis.yml index 6afdc3d..9a96a88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/chai-immutable.js b/chai-immutable.js index 77f5842..c22df6c 100644 --- a/chai-immutable.js +++ b/chai-immutable.js @@ -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) { @@ -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}', @@ -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)