diff-json
diff-json copied to clipboard
Fails for case of newly added property with a value of null
A simple test case:
it 'should properly handle new null property', ->
before = {}
after = { newProp: null }
changesets.applyChanges before, changesets.diff before, after
expect(after).to.eql before
Fails with "TypeError: Cannot read property 'length' of undefined"
https://github.com/viruschidai/diff-json/blob/4356e69d6755f3cfa7a2396e33b28a8797a834b0/src/changesets.coffee#L212
should probably be:
if !change.changes
In its current form applyChanges calls applyBranchChanges for the add of a new property with a value of null. applyBranchChanges expects a changes array to exist on the change and calls length on undefined.
Yep, this happens :( Any expected fix?
Anyone wants to PR?
Shit, I just wasted a lot of time before checking the issues here 🤦
Wonder why this hasn't been picked up in two years @viruschidai? But happy to find a solution.
#20
In the meantime you can do something like: yarn add https://github.com/0x80/diff-json\#topic/fix-newly-added-null
@viruschidai Could you please release v2.0.1 with this fix?
I waited a year before you merged the PR in April, but there has been no new release so I still can't use normal npm version control for this library.