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: op type error with an new empty string property #545

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/collection-diff/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function diff(obj1, obj2, pathConverter) {
var obj1AtKey = obj1[key];
var obj2AtKey = obj2[key];

if(!(key in obj1) && obj2AtKey) {
if(!(key in obj1) && (key in obj2)) {
var obj2Value = obj2AtKey;
permutation.add.push({
op: 'add',
Expand Down
2 changes: 1 addition & 1 deletion packages/collection-diff/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function diff(obj1, obj2, pathConverter) {
var obj1AtKey = obj1[key];
var obj2AtKey = obj2[key];

if(!(key in obj1) && obj2AtKey) {
if(!(key in obj1) && (key in obj2)) {
var obj2Value = obj2AtKey;
permutation.add.push({
op: 'add',
Expand Down
16 changes: 15 additions & 1 deletion test/collection-diff/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var {
var compare = require('../../packages/collection-compare');

test('flat objects', function(t) {
t.plan(8);
t.plan(10);

var obj1 = {a: 4, b: 5};
var obj2 = {a: 3, b: 5};
Expand Down Expand Up @@ -58,6 +58,20 @@ test('flat objects', function(t) {
{op: 'replace', path: ['b'], value: 5},
])
);
t.ok(
compare(diff(obj3, obj4), [
{ op: 'remove', path: [ 'c' ] },
{ op: 'replace', path: [ 'a' ], value: 3 },
{ op: 'add', path: [ 'b' ], value: null }
])
);
t.ok(
compare(diff(obj4, obj3), [
{ op: 'remove', path: [ 'b' ] },
{ op: 'replace', path: [ 'a' ], value: 4 },
{ op: 'add', path: [ 'c' ], value: 5 }
])
);
});

test('flat null and undefined', function(t) {
Expand Down