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

fix(deep-assign): add deepAssign to objects in strategy create's #1

Merged
merged 5 commits into from
May 21, 2017

Conversation

ksafranski
Copy link
Contributor

No description provided.

@ksafranski ksafranski self-assigned this May 21, 2017
@codecov
Copy link

codecov bot commented May 21, 2017

Codecov Report

Merging #1 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master     #1   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines          43     47    +4     
=====================================
+ Hits           43     47    +4
Impacted Files Coverage Δ
src/plugins/json.js 100% <100%> (ø) ⬆️
src/plugins/object.js 100% <100%> (ø) ⬆️
src/plugins/array.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 887105b...f94abe3. Read the comment docs.

// Apply modifications and return
return without(mods.remove, [ ...data ]).concat([ ...mods.add ])

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",

Choose a reason for hiding this comment

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

screen shot 2017-05-21 at 9 41 19 am

sindresorhus/deep-assign#26

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.

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' ])

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.

@dvdzkwsk
Copy link

👻

@ksafranski ksafranski merged commit 52e36d3 into master May 21, 2017
@ksafranski ksafranski deleted the fix/deep-assign branch May 21, 2017 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants