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 1 commit
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
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ notifications:
on_success: never
on_failure: always

before_script:
- 'if [ "$IMMUTABLE_VERSION" ]; then npm install immutable@$IMMUTABLE_VERSION; fi'
gugu marked this conversation as resolved.
Show resolved Hide resolved
env:
- IMMUTABLE_VERSION=3
gugu marked this conversation as resolved.
Show resolved Hide resolved
- IMMUTABLE_VERSION=4.0.0-rc.12
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this accept a broader version, such as IMMUTABLE_VERSION=4 or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only after release, this version does not follow semver :(

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I realized that, that's why I went with ^4.0.0-rc. When 4 gets stable, I'll revise that.

# Identifies `a.b.c-xxx.n` tags as pre-releases, and `a.b.c` as stable releases
before_deploy: |
function dist_tag() {
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