Skip to content

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

Closed
devand123 wants to merge 9 commits intochaijs:masterfrom
devand123:master
Closed

issue 184: assert.property should pass for defined keys with undefined values#210
devand123 wants to merge 9 commits intochaijs:masterfrom
devand123:master

Conversation

@devand123
Copy link
Copy Markdown

Fixes #184

@coveralls
Copy link
Copy Markdown

Coverage Status

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

@vesln
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

Coverage Status

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

@jezeniel
Copy link
Copy Markdown

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

@FredKSchott
Copy link
Copy Markdown

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

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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