-
Notifications
You must be signed in to change notification settings - Fork 0
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
fix(deep-assign): add deepAssign to objects in strategy create's #1
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 4 4
Lines 43 47 +4
=====================================
+ Hits 43 47 +4
Continue to review full report at Codecov.
|
src/plugins/array.js
Outdated
// Apply modifications and return | ||
return without(mods.remove, [ ...data ]).concat([ ...mods.add ]) |
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.
I think what you want is:
without(mods.remove, [...data.map(assign)].concat([...mods.add.map(assign)])
You're already shallow-cloning the array with ...[]
, so unless deep-assign
maps over all array elements and deep clones them, that's what you'll need to do yourself.
package.json
Outdated
@@ -52,6 +52,7 @@ | |||
] | |||
}, | |||
"dependencies": { | |||
"deep-assign": "^2.0.0", |
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.
Not sure what the deal is here. Perhaps consider using https://www.npmjs.com/package/lodash.merge, which performs a deep merge w/o pulling in the entirety of lodash.
test/src/plugins/array.spec.js
Outdated
const actual = array.create(original, { | ||
add: [ 'baz' ], | ||
remove: [ 'bar' ] | ||
}) | ||
expect(original).to.deep.equal([ 'foo', 'bar' ]) | ||
expect(actual).to.deep.equal([ 'foo', 'baz' ]) | ||
expect(original).to.deep.equal([ 'foo', { fizz: 'buzz' }, 'bar' ]) |
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.
May want to perform two comparisons here, one to check that references are broken, and the other to confirm deep equality:
const obj = { fizz: 'buzz' }
const original = [ 'foo', { fizz: 'buzz' }, 'bar' ]
// compare references
expect(original[1]).to.not.equal(actual[1])
// compare equality
expect(original[1]).to.deep.equal(actual[1])
This way you're ensuring the feature fundamentally offered by fixd
, namely that objects cannot be mutated between tests.
👻 |
No description provided.