Support Immutable with chai's property assertions #43
Conversation
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. Hey what the hell @coveralls, you commenting here is supposed to be disabled! |
Ping! :0) |
@@ -540,5 +540,97 @@ | |||
assert.sizeOf = function (collection, expected) { | |||
new Assertion(collection).size(expected); | |||
}; | |||
|
|||
/** | |||
* ### .property(path, value) |
astorije
Apr 11, 2016
Owner
For alphabetical sorting consistency, would you mind moving this addition between keys
and size
, in the BDD reference section of the code please?
For alphabetical sorting consistency, would you mind moving this addition between keys
and size
, in the BDD reference section of the code please?
* @api public | ||
*/ | ||
function assertProperty(_super) { | ||
return function (path, val, msg) { |
astorije
Apr 11, 2016
Owner
Note that providing a custom message is not available in any other assertion of this plugin. I would prefer we don't include it in this PR for this assertion only.
If you really need custom messages, you can open an issue to solve that globally and we'll start with this assertion.
Does that make sense?
Note that providing a custom message is not available in any other assertion of this plugin. I would prefer we don't include it in this PR for this assertion only.
If you really need custom messages, you can open an issue to solve that globally and we'll start with this assertion.
Does that make sense?
var value; | ||
|
||
if (!Immutable.Iterable.isIterable(obj)) { | ||
return _super.apply(this, arguments); |
astorije
Apr 11, 2016
Owner
Could you follow the same pattern as other assertions, that is, having this check as high in the function as possible and returning _super.apply(this, arguments);
in an else
statement at the very end?
Probably not the nicest way to do so, but at least consistent with the rest of the file.
Could you follow the same pattern as other assertions, that is, having this check as high in the function as possible and returning _super.apply(this, arguments);
in an else
statement at the very end?
Probably not the nicest way to do so, but at least consistent with the rest of the file.
Hey @scottnonnenberg, sorry for being silent, busy and all. The biggest thing I need to address with you is the format of the deep properties.
Depending on these questions, I think we could either switch to the dot/bracket-notation or, if the |
Quick |
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
Squash complete! |
Awesome, |
Hello both, Fantastic work ! |
@JalilArfaoui Will do ASAP, I need to update the doc first. Stay tuned |
@JalilArfaoui, this was finally released in v1.6.0: https://github.com/astorije/chai-immutable/releases/tag/v1.6.0 |
Property and deep property assertions, because I really like that syntax when I use
chai
with plain objects. :0)Based on original
property()
here: https://github.com/chaijs/chai/blob/8e8a728921085351ecd050cd606b2ef6a1fb1338/lib/chai/core/assertions.js#L881Like other methods in
chai-immutable
, falls back to original chai methods if the target object is notisIterable()
.100% code coverage for newly-added code. Also, I noticed that changing
chai.config.truncateThreshold
can make display of Immutable objects a lot nicer.