-
Notifications
You must be signed in to change notification settings - Fork 75
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
Invalidate array of objects with only a partial object value #77
Conversation
This threw in code < 3.0.0. However, in 3.0.0, we added a breaking change to default to deep comparison. I think if |
i agree, i think this works appropriately as it is |
OK. Closing then. |
Maybe I don't understand. Why do you say it works as intended? I don't see how it is related to the deep flag. There is the what is the difference between Code.expect([{ a: 1, b: 1 }]).to.include({ a: 1 }); and Code.expect([{ a: 1, b: 1 }]).to.part.include({ a: 1 }); How would you say an array of objects 'fully' (not partially) includes an object? what I would expect Code.expect([{ a: 1, b: 1 }]).to.include({ a: 1 }); // throws
Code.expect([{ a: 1, b: 1 }, { c: 1, d: 1}]).to.include({ a: 1, b: 1}); // passes
Code.expect([{ a: 1, b: 1 }]).to.part.include({ b: 1}); // passes
Code.expect([{ a: 1, b: 1 }]).to.part.include({ d: 1}); // throws |
|
OK, but you cannot use shallow, and effectively Code.expect([{a:1, b: 2}]).to.part.include({a: 1}) Code.expect([{a:1, b: 2}]).to.include({a: 1}) means the same thing And even if that's the meaning in Hoek, it doesn't mean it should be the default in here - especially that you cannot (at least I haven't found a way) assert that an object exists in an array Hoek.contain has |
if you want to validate that the whole object exists in the array, pass the whole object as the Code.expect([{ a: 1, b: 2 }]).to.include({ a: 1, b: 2 }); works just fine. isn't that what you're trying to do? |
Hoek.contain([{ a: 1, b: 2 }, { d: 1 }], { b: 2, a: 1 }, { deep: true }) === true
Hoek.contain([{ a: 1, b: 2 }, { d: 1 }], { b: 2 }, { deep: true }) === true
Hoek.contain([{ a: 1, b: 2 }, { d: 1 }], { b:2 }, { deep: true, part: false }) === false
Hoek.contain([{ a: 1, b: 2 }, { d: 1 }], { b: 2, a: 1 }, { deep: true, part: false }) === true |
it doesn't work as I expected because Code.expect([{ a: 1, b: 2 }]).to.include({ a: 1}); // doesn't throw (which is exactly the test I added in the PR) |
another issue that I think stems from this one: Code.expect([{ a: 1, b: 2 }]).to.include({}) // doesn't throw |
you're right in that we could potentially add a flag to allow disabling partial matches, at the very least more clear documentation would be helpful. what exactly are you trying to test? |
@nlf with it being recursive, shouldn't this pass: Code.expect([{ a: 1, b: 2 }]).to.part.include({ a: 1, d: 4 }); Since this does: Code.expect({ a: 1, b: 2 }).to.part.include({ a: 1, d: 4 }); |
"recursive" was me misspeaking, it's not actually recursive, the behavior is because |
but here part=true is not the default, it is set to true only if you use the part in the expectation chain, so you cannot set it to false directly I'm trying to test an object is within an array, specifically I'm testing mongodb indices, and I want to check an index is present in an array of indices. |
It might make sense to do this then for this._flags.part = !!this._flags.part; |
@cjihrig that's what I initially did, but I thought it is a little bit more expressive this way |
Marking this as semver-major. |
Was there release note for this? |
I just did a normal release. Added the |
Next time is would be better to at least give the full details in the top of the issue. I had to actually read this entire thread to figure out what changed. That wasn't great. |
You are right - I thought the test was good enough to describe it. I should have at least put an abbreviation of it in the description of the issue |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Before this PR
would not throw. After this PR, it throws.
It might be an issue with Hoek, though it is possible that the default value for
part
flag is true inHoek.contain