-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
Deep flag support for keys assertion #668
Conversation
Hello everyone, I'll finish the items left on this one since we're getting close to releasing |
@lucasfcosta my work with refactoring loupe is quite a ways off. We can probably apple a simple fix for #662 though, to get it working with Maps and Sets for now. |
@keithamus seems like a good idea. Let's solve this one that way then so we can get this merged. |
a72431a
to
a911ec0
Compare
This one is done! |
a911ec0
to
2f4a242
Compare
@@ -778,7 +794,7 @@ describe('assert', function () { | |||
var errMap = new Map(); | |||
|
|||
errMap.set({1: 20}, 'number'); | |||
|
|||
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 see trailing spaces 😱
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.
My vim does only removes it when there's an .editorconfig
file in the root folder of where the file is 😢
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've just fixed that, thanks for noticing 😄
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.
haha
I add a .editorconfig
file on my home with some rules that I always want.
I think it goes looking upwards until it finds one
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.
Yes it does, great idea 😄
2f4a242
to
e8bde1c
Compare
Awesome work! What could we do to remember enabling these commented tests when #662 gets solved? |
@vieiralucas Yes, I think that would be ideal. |
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.
@lucasfcosta Excellent work sir, this will be a fine addition to Chai. I have a few small comments sprinkled throughout (it only looks like a lot of comments cause I repeated them wherever applicable).
, str | ||
, ok = true | ||
, mixedArgsMsg = 'when testing keys against an object or an array you must give a single Array|Object|String argument or multiple String arguments'; | ||
|
||
if (_.type(obj) === 'map' || _.type(obj) === 'set') { | ||
str = isDeep ? 'deeply ' : ''; |
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 realize messages aren't being tested yet due to an issue with inspect and sets/maps, but just noting that I believe str
will get overwritten here.
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.
You are right!
I'm going to use a different variable to store that String, thanks 😄
assert.hasAnyDeepKeys = function (obj, keys, msg) { | ||
if (keys === undefined) { | ||
new Assertion(obj, msg).to.have.any.deep.keys(); | ||
} |
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.
What if the undefined
check was at the top of the actual assertKeys
function instead?
* | ||
* @name doesNotHaveAllKeys | ||
* @param {Mixed} object | ||
* @param {...String|Array|Object} keys |
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.
It doesn't look to me like the ...String
style of the keys
argument is supported here.
* | ||
* @name hasAllDeepKeys | ||
* @param {Mixed} object | ||
* @param {...String|Array|Object} keys |
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.
It doesn't look to me like the ...String
style of the keys
argument is supported here.
/** | ||
* ### .containsAllDeepKeys(object, [keys], [message]) | ||
* | ||
* Asserts that `object` contains all of the `keys` provided. |
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.
Even though it's shown in the example, probably worth mentioning explicitly that the object can have more keys than those provided, just to contrast with hasAll
@@ -877,6 +903,22 @@ describe('assert', function () { | |||
errSet.add({1: 20}); | |||
errSet.add('number'); | |||
|
|||
// Tests for the deep variations of the keys assertion |
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'm thinking a test should be added to the non-deep variety of assertion above demonstrating that it uses strict equality instead of deep. For example:
assert.doesNotHaveAnyKeys(testSet, {thisIs: 'anExampleObject'});
@@ -1205,6 +1205,27 @@ describe('expect', function () { | |||
expect(testMap).to.not.have.any.keys([20, 1, {13: 37}]); | |||
expect(testMap).to.not.have.all.keys([aKey, {'iDoNot': 'exist'}]); | |||
|
|||
// Using the same assertions as above but with `.deep` flag instead of using referential equality |
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.
Same thing as mentioned in the assert interface tests about adding a non-deep test to demonstrate strict equality.
@@ -1285,6 +1316,26 @@ describe('expect', function () { | |||
expect(testSet).to.not.have.any.keys([20, 1, {13: 37}]); | |||
expect(testSet).to.not.have.all.keys([aKey, {'iDoNot': 'exist'}]); | |||
|
|||
// Using the same assertions as above but with `.deep` flag instead of using referential equality |
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.
Same thing as mentioned in the assert interface tests about adding a non-deep test to demonstrate strict equality.
@@ -1051,6 +1051,23 @@ describe('should', function() { | |||
testMap.should.not.have.any.keys([20, 1, {13: 37}]); | |||
testMap.should.not.have.all.keys([aKey, {'iDoNot': 'exist'}]); | |||
|
|||
// Using the same assertions as above but with `.deep` flag instead of using referential equality |
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.
Same thing as mentioned in the assert interface tests about adding a non-deep test to demonstrate strict equality.
@@ -1131,6 +1158,26 @@ describe('should', function() { | |||
testSet.should.not.have.any.keys([20, 1, {13: 37}]); | |||
testSet.should.not.have.all.keys([aKey, {'iDoNot': 'exist'}]); | |||
|
|||
// Using the same assertions as above but with `.deep` flag instead of using referential equality |
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.
Same thing as mentioned in the assert interface tests about adding a non-deep test to demonstrate strict equality.
e8bde1c
to
a0a5fc1
Compare
Here it is! Please let me know if I missed something. I'd also like to add a note here for my future self: it would be nice to refactor these methods in order for them to support what I've said in this comment and also throw an error indicating keys are required when no keys are passed for the other combination of keys assertions other than the ones I mentioned there. |
a0a5fc1
to
816b5a3
Compare
@lucasfcosta I like the extra tests you added since the last commit on the |
@meeber, seems adequate! |
816b5a3
to
9498811
Compare
@meeber here it is! |
@lucasfcosta Well done sir! LGTM! The only way this could be better is if we add another 5 or 6 interfaces so you can add all of the same tests on those interfaces too! Wouldn't that be fun?! :D Pinging @keithamus and @vieiralucas! |
As I have said previously, this is awesome work. LGTM |
This adds support for the
deep
flag on thekeys
assertion (for Maps/Sets) as I've talked to @keithamus at #633.This PR should include:
deep
flag on this assertionshould
interfaceexpect
interfaceassert
interfaceassert
interfaceCurrently the only thing missing are the bindings for these assertions on the assert interface, I didn't do it yet because I'm not sure if adding lots of bindings for this to the
assert
interface would be cool. If we added bindings for every possible combination of thekeys
assertion flags we would have:IMO we should have all of them on the
assert
interface because I think it should have the same features as the other interfaces do, but I just wanted to make sure you guys agree with me before adding all these bindings.Important Detail:
Currently we need to fix #662 in order to enable all tests, so I think we may keep this open but on hold until we've got
inspect
to work properly formaps
andsets
so we can fully test this.What's your opinion on this?
Thanks in advance, please feel free to point any possible mistakes/improvements 😄