Skip to content
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

issue 184: assert.property should pass for defined keys with undefined values #210

Closed
wants to merge 9 commits into from

Conversation

devand123
Copy link

Fixes #184

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling bd87d2c on devand123:master into f82f43f on chaijs:master.

@vesln
Copy link
Member

vesln commented Nov 16, 2013

That's a great start. Please consider the following too:

var foo = { bar: { foo: undefined }};
assert.deepProperty(foo, 'bar.foo')

Unfortunately, it's currently failing.

@logicalparadox
Copy link
Member

I agree this behavior needs to be changed to support the existence of deep properties and not just undefined values. I think changes will need to be made to util/getPathValue.js in order for this to work properly. However, a little discussion first.

Building on @vesln 's example:

var obj = { foo: { bar: undefined }};
assert.deepProperty(obj, 'foo.bar'); // => should pass

This makes sense. The deep property exists even though it is undefined. But what about:

/* a */ assert.deepProperty(obj, 'foo.bar.baz'); // => should fail?
/* b */ assert.deepProperty(obj, 'foo.bar[0]'); // => should fail?

I think a reasonable expectation here is that:

  • a: since bar is undefined, baz cannot exist. assertion failed
  • b: since bar is not an array, index 0 cannot exist. assertion failed

This is my opinion anyway. Pinging @vesln @domenic for your thoughts.

Also, @devand123: There is a lot of change/revert going on in your PR. Can you please squash all your commits into a single commit then force push to your fork? It will update this PR automatically.

…n an object with a value of undefined.

convert to camel case styling.

Fixing test.

issue: 184 Make sure properties assigned with undefined value still test true for assert.property

change assertion back to original file

Revert "issue: 184 Make sure properties assigned with undefined value still test true for assert.property"

This reverts commit 8fd7cf6.

issue: 184 Make sure properties assigned with undefined value still test true for assert.property

Issue 184, allowing assert.property to not fail for undefined values for NON-deep objects.
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 3125bc3 on devand123:master into f82f43f on chaijs:master.

@jezeniel
Copy link

👍 for this. This behavior should be changed. But sadly this issue remains.

@FredKSchott
Copy link

👍 👍 objects can have undefined properties, this should really be fixed

@@ -1699,8 +1699,11 @@ module.exports = function (chai, _) {
throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
}
} else {
var finalValue = value || flag(this, 'deep') ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't include changes to this file. It will get updated on releases.

@keithamus
Copy link
Member

Hey @devand123, this looks like a good PR. Thanks for adding some good test coverage. If you could follow @charlierudolph's points, and maybe add some more tests to verify that @vesln's code would work, then I think we could look to getting this merged 😄

@keithamus
Copy link
Member

@devand123 - do you have any time for this? It'd be great to see the PR updated with the above points ⬆️

@joshperry
Copy link
Contributor

Wow, I didn't realize there was a PR for this already. I was just running into this problem doing some TDD and wrote #308. Happy to help with this if I can, I'd love to get fix into the mainline.

@keithamus
Copy link
Member

Closing this, as we went ahead with @joshperry's version. Thanks for all of your efforts with this though @devand123 - please don't let it put you off from making more great pull requests!

@keithamus keithamus closed this Dec 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Property assertion fails when object has a field with undefined values
9 participants