-
Notifications
You must be signed in to change notification settings - Fork 16
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
Use Iterable.isIterable for Immutable check #36
Conversation
Hey @jakelazaroff, thanks for your contribution! Good catch too! |
No problem 😁 I'll update the PR in a few minutes. |
b34220f
to
ef282de
Compare
@@ -68,6 +71,12 @@ describe('chai-immutable (' + typeEnv + ')', function () { | |||
it('should fail using `not` given an empty collection', function () { | |||
fail(function () { expect(new List()).to.not.be.empty; }); | |||
}); | |||
|
|||
if (typeEnv === 'Node.js') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out how to load a different copy of Immutable for the Phantom tests, but I don't think it should really be a problem anyway since in a browser everything will just use whatever's on the window
object. I also don't love wrapping it
s inside a conditional — let me know if there's a way you'd rather I write this!
ef282de
to
047f61b
Compare
@astorije Updated the PR but there's some work to be done still. After adding the tests I realized there were more It's not exactly clear (to me, at least) how these map to the static methods listed here: https://facebook.github.io/immutable-js/docs/#/Iterable/isIterable I'm guessing |
Also: trying to figure out now how to replace these assertions with the Iterable static methods: https://github.com/astorije/chai-immutable/blob/master/chai-immutable.js#L312 |
38d485d
to
feeb3af
Compare
@astorije Should be fixed! I replaced the For the Looks like anything that returns true for Let me know if there's anything you'd like me to add/change 😄 |
Anything I can do to help get this merged? |
Hi @jakelazaroff, so sorry I have been very busy and I must admit I dropped the ball, shame on me... I don't like the idea of wrapping Thanks again! |
No worries! I'll try to figure out a way to get Phantom to load two different copies of Immutable; that should avoid the test-skipping issue entirely. |
@@ -5,6 +5,7 @@ if (!chai) { | |||
var chai = require('chai'); | |||
var chaiImmutable = require('../chai-immutable'); | |||
var Immutable = require('immutable'); | |||
var otherImmutable = require('../node_modules/immutable/dist/immutable.min.js'); | |||
|
|||
chai.use(chaiImmutable); | |||
typeEnv = 'Node.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way to do that, somewhat cleaner and most likely compatible with PhantomJS, but probably a bit more difficult to achieve, is to deep clone/duplicate Immutable
right before var assert = chai.assert;
and assign this copy to your otherImmutable
(that could be renamed clonedImmutable
accordingly).
Then I believe you can remove all those if (typeEnv === 'Node.js')
and let the runners test these.
Would you mind exploring this idea before we can merge?
Thanks!
@jakelazaroff, I left you a comment inline that might address this problem. Let me know what you think and when you think you'll reach to a solution: I'm sorry to see your PR hanging around and would like to help you having it ready for production! |
@jakelazaroff, do you have any update on this? :-) |
@jakelazaroff, ping ping ping? :-) |
@astorije Crap, I seriously dropped the ball on this. I'll update by the end of the week. Sorry about the delay! |
@astorije Your hunch worked! Should be good to go now. |
@@ -68,6 +82,10 @@ describe('chai-immutable (' + typeEnv + ')', function () { | |||
it('should fail using `not` given an empty collection', function () { | |||
fail(function () { expect(new List()).to.not.be.empty; }); | |||
}); | |||
|
|||
it('should work if using different copies of Immtuable', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo at Immtuable
.
Hi @jakelazaroff, sorry I didn't get back to you earlier! Also, could you squash your commits? :-) |
d8e2005
to
7c8697f
Compare
Done! I think this should do it :) |
Very nice job @jakelazaroff, sorry it took so long! |
Use Iterable.isIterable for Immutable check
Awesome, thanks so much! Side note: if you ever need to use this with karma, I created this adapter for it https://github.com/jakelazaroff/karma-chai-immutable |
Right now the check for whether an object is Immutable uses
instanceof Collection
, which returns false if different modules are using different copies of Immutable.This PR replaces that with
Immutable.Iterable.isIterable
as advised here: http://stackoverflow.com/questions/31907470/how-to-check-if-object-is-immutable