-
Notifications
You must be signed in to change notification settings - Fork 117
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
Add toIncludeKeys and toExcludeKeys #87
Conversation
@@ -286,6 +286,32 @@ expect('hello world').toExclude('goodbye') | |||
expect('hello world').toNotContain('goodbye') | |||
``` | |||
|
|||
### toIncludeKeys | |||
> `expect(object).toIncludeKeys(keys, [hasKey], [message])`<br> |
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 not sure I understand what the hasKey
argument is for.
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.
For consistency with other methods, also someone might want to use a check which includes properties in the prototype chain. The has
module only checks immediate properties.
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 believe toInclude
and toExclude
only deal with own properties - I think we should be consistent here. In addition, "own" should be the default, I'd think.
I'd also want a separate method to deal with inherited properties, rather than a boolean switch.
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's not a boolean switch, it's an optional comparator function like toInclude
has 😊
I just updated the docs, reread and if you're still opposed I can take it out. I only added the parameter for some consistency with the comparater
function in toInclude
.
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.
ah - in that case let's make it a comparator
argument, just the same.
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.
😊 👍
@@ -364,6 +365,42 @@ class Expectation { | |||
return this | |||
} | |||
|
|||
toIncludeKeys(keys, hasKey, message) { |
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.
let's call hasKey
comparator
, for consistency with the docs
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.
Done 👍
2180258
to
1cff71c
Compare
@@ -286,6 +286,32 @@ expect('hello world').toExclude('goodbye') | |||
expect('hello world').toNotContain('goodbye') | |||
``` | |||
|
|||
### toIncludeKeys |
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.
Let's write this as toIncludeKey(s)
This looks great. Thanks, @calebmer! I made a few comments that I hope will help. |
👍 Updated this PR and #86. I want to complement again core contributors on how clean this code base is. Jumping into it is very fun and easy. |
Thanks, @calebmer :) |
This was a feature I originally included in #86, but was asked to move it to its own PR. Therefore, tada 🎉
This PR currently adds two methods to
Expectation
,toIncludeKeys
andtoExcludeKeys
which work as expected.