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

Support Immutable with chai's property assertions #43

Merged
merged 1 commit into from Apr 20, 2016
Merged

Support Immutable with chai's property assertions #43

merged 1 commit into from Apr 20, 2016

Conversation

scottnonnenberg
Copy link
Contributor

Property and deep property assertions, because I really like that syntax when I use chai with plain objects. :0)

var obj = Immutable.fromJS({ x: 1 });
expect(obj).to.have.property('x', 1);

var obj = Immutable.fromJS({ x: 1, y: { x: 2, y: 3 } });
expect(obj).to.have.deep.property(['y', 'x'], 2);

Based on original property() here: https://github.com/chaijs/chai/blob/8e8a728921085351ecd050cd606b2ef6a1fb1338/lib/chai/core/assertions.js#L881

Like other methods in chai-immutable, falls back to original chai methods if the target object is not isIterable().

100% code coverage for newly-added code. Also, I noticed that changing chai.config.truncateThreshold can make display of Immutable objects a lot nicer.

@scottnonnenberg
Copy link
Contributor Author

Fixes #9, #41, #14.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 98.315% when pulling 56eaf4a on scottnonnenberg:property into 655d187 on astorije:master.

@astorije
Copy link
Owner

Waouh @scottnonnenberg, thanks a lot for this, it looks like tremendous work! As a matter of fact, this is something I wanted to tackle fairly soon as I saw different requests about it coming up.
Give me a few days to review thoroughly and get back to you, and feel free to ping here if you think I forgot.

Hey what the hell @coveralls, you commenting here is supposed to be disabled!

@scottnonnenberg
Copy link
Contributor Author

Ping! :0)

@@ -540,5 +540,97 @@
assert.sizeOf = function (collection, expected) {
new Assertion(collection).size(expected);
};

/**
* ### .property(path, value)
Copy link
Owner

Choose a reason for hiding this comment

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

For alphabetical sorting consistency, would you mind moving this addition between keys and size, in the BDD reference section of the code please?

@astorije
Copy link
Owner

Hey @scottnonnenberg, sorry for being silent, busy and all.
I started briefly looking into your work, it's awesome, gonna be a great addition to the plugin!

The biggest thing I need to address with you is the format of the deep properties.
Chai "use[s] dot- and bracket-notation for deep references into objects and arrays", while you went for the same argument as passed to Iterable#getIn(). Since this plugin aims at providing transparent Chai assertions for Immutable, I mention using same notation as Chai's in #14. My questions are as follows:

  • Why did you choose one over the other?
  • Is there an easy equivalence between the getIn notation and the dot/bracket-notation, specifically for the indices? I don't see the use of indices in your tests.

Depending on these questions, I think we could either switch to the dot/bracket-notation or, if the getIn notation makes sense (it's more of a use case question than a technical one), if we can convert one to the other when receiving it as an input.

@scottnonnenberg
Copy link
Contributor Author

Quick split() call and we support both! :0)

@astorije
Copy link
Owner

Great work, @scottnonnenberg! Could you squash your commits into one commit before I can merge, please?

Reorder methods for proper alphabetical sorting
Remove msg parameter
Match isIterable check with other methods in file
property() - Add an array index deep property test
property: Support string deep property syntax
Fix alphabetical in tests
More test reordering
@scottnonnenberg
Copy link
Contributor Author

Squash complete!

@astorije
Copy link
Owner

Awesome, 👍 and merging!

@astorije astorije merged commit 12536fd into astorije:master Apr 20, 2016
@JalilArfaoui
Copy link

Hello both, Fantastic work !
Could you release a new version ?
I'm using latest npm (1.5.4) which does not support this ...

@astorije
Copy link
Owner

@JalilArfaoui Will do ASAP, I need to update the doc first. Stay tuned 😄

@astorije
Copy link
Owner

@JalilArfaoui, this was finally released in v1.6.0: https://github.com/astorije/chai-immutable/releases/tag/v1.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants