Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.equal now checks for isImmutable instead of isIterable #213

Merged
merged 6 commits into from
Apr 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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