-
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
Modify the object version of toInclude #85
Conversation
This PR introduces following changes: * Traverse both enumerable name keys and enumerable symbol keys. `expect({a: 1}).toInclude({[Symbol()]: 1}) // fail` * Always pass a assertion with an empty object as an expected value. `expect({a: 1}).toInclude({}) // pass` BREAKING CHANGE: compare an empty object property to its corresponding actual property. Before: `expect({}).toInclude({a: {}}) // pass` After: `expect({a: 1}).toInclude({a: {}}) // fail` Closes mjackson#82
It is a rebased and squashed version of #83. I also rewrote the commit message. |
@wuct Thanks! It'd have been preferable to modify the original PR instead of opening a new one, but this will do :-) |
@ljharb Thank you, too! I have learnt a lot from you 😊 |
@wuct afaik, only pushing a branch deletion to the remote will trigger the PR to close. You need to instead, actually force push, in order to update a PR in-place. |
@mjackson @elado Do you consider this a breaking change, or a bugfix on the initial I originally classified it as a breaking change because it will throw in cases where it previously did not - however, in those cases, I suspect users want it to throw, meaning this would be revealing failing tests. |
From #82:
I don't expect this to fail. The original object includes a key |
@elado in your situation i would not expect it to fail. However, if |
Actually, perhaps not - as long as the value on the LHS is not If @elado concurs, then @wuct, can you change this so that an empty object on the RHS only fails (for any key) when the LHS is |
I think So what might be missing is the type check on both values. |
That seems equally reasonable to me. |
I agree with @elado. We should compare partial objects only when both types are |
@@ -0,0 +1,19 @@ | |||
import objectKeys from 'object-keys' | |||
|
|||
const ownKeys = (object) => { |
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.
Perhaps we could call this ownEnumerableKeys
to avoid confusing it with Reflect.ownKeys
?
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.
isn't it meant to be a polyfill for Reflect.ownKeys?
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.
@ljharb Not AFAICT. It restricts the result of Reflect.ownKeys
to enumerable 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.
ah, k
Thanks for merging :) |
This PR introduces following changes:
Traverse both enumerable name keys and enumerable symbol keys.
expect({a: 1}).toInclude({[Symbol()]: 1}) // fail
Always pass a assertion with an empty object as an expected value.
expect({a: 1}).toInclude({}) // pass
BREAKING CHANGE: compare an empty object property to its corresponding actual property.
Before:
expect({}).toInclude({a: {}}) // pass
After:
expect({a: 1}).toInclude({a: {}}) // fail
Closes #82