-
Notifications
You must be signed in to change notification settings - Fork 130
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
null check in nested key resolution #32
Conversation
The build is failing because we're not getting 100% code coverage with these changes. You could probably just add an item to this list where |
src/__tests__/index.js
Outdated
@@ -105,7 +105,7 @@ const tests = { | |||
}, | |||
'can handle objected with nested keys': { | |||
input: [ | |||
[{name: {first: 'baz'}}, {name: {first: 'bat'}}, {name: {first: 'foo'}}], | |||
[{name: {first: 'baz'}}, {name: {first: 'bat'}}, {}], |
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.
Could you actually add another item to the array? This test is also ensuring that we filter out the foo item.
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.
oh right gotcha.
src/index.js
Outdated
@@ -251,7 +251,7 @@ function getItemValues(item, key) { | |||
// handle nested keys | |||
value = key | |||
.split('.') | |||
.reduce((itemObj, nestedKey) => itemObj[nestedKey], item) | |||
.reduce((itemObj, nestedKey) => itemObj && itemObj[nestedKey] ? itemObj[nestedKey] : null, item) |
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.
The second part of the &&
is unnecessary here
Codecov Report
@@ Coverage Diff @@
## master #32 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 1 1
Lines 104 104
Branches 29 30 +1
=====================================
Hits 104 104
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #32 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 1 1
Lines 104 104
Branches 29 30 +1
=====================================
Hits 104 104
Continue to review full report at Codecov.
|
Thanks a bunch! |
What:
Why: #31
How:
Checklist: