Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c91000c

Browse files
FrozenPandazvsavkin
authored andcommittedMar 10, 2020
fix(core): fix json diff and implicitJsonChanges part 2
1 parent 6a71284 commit c91000c

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed
 

‎packages/workspace/src/utils/json-diff.spec.ts

+32
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,38 @@ describe('jsonDiff', () => {
108108
});
109109
});
110110

111+
it('should work for added array values', () => {
112+
const result = jsonDiff(
113+
{
114+
rules: undefined
115+
},
116+
{
117+
rules: ['rule1']
118+
}
119+
);
120+
121+
expect(result).toEqual(
122+
expect.arrayContaining([
123+
{
124+
type: DiffType.Modified,
125+
path: ['rules'],
126+
value: {
127+
lhs: undefined,
128+
rhs: ['rule1']
129+
}
130+
},
131+
{
132+
type: DiffType.Added,
133+
path: ['rules', '0'],
134+
value: {
135+
lhs: undefined,
136+
rhs: 'rule1'
137+
}
138+
}
139+
])
140+
);
141+
});
142+
111143
it('should work for added array items', () => {
112144
const result = jsonDiff(
113145
{

‎packages/workspace/src/utils/json-diff.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function jsonDiff(lhs: any, rhs: any): JsonChange[] {
4949
}
5050
});
5151
}
52-
return typeof lhsValue === 'object';
52+
return typeof lhsValue === 'object' || Array.isArray(lhsValue);
5353
});
5454

5555
walkJsonTree(rhs, [], (path, rhsValue) => {
@@ -63,9 +63,8 @@ export function jsonDiff(lhs: any, rhs: any): JsonChange[] {
6363
rhs: rhsValue
6464
}
6565
});
66-
return false;
6766
}
68-
return typeof rhsValue === 'object';
67+
return typeof rhsValue === 'object' || Array.isArray(rhsValue);
6968
});
7069

7170
return result;

0 commit comments

Comments
 (0)
Please sign in to comment.