Skip to content

Commit 19e2d20

Browse files
committed
Add tests for fastMerge
1 parent 1b8c804 commit 19e2d20

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/unit/fastMergeTest.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ const testObjectWithNullValuesRemoved: DeepObject = {
3636
},
3737
};
3838

39+
const testMergeChanges: DeepObject[] = [
40+
{
41+
b: {
42+
d: {
43+
h: 'h',
44+
},
45+
},
46+
},
47+
{
48+
b: {
49+
d: null,
50+
h: 'h',
51+
},
52+
},
53+
];
54+
3955
describe('fastMerge', () => {
4056
it('should merge an object with another object and remove nested null values', () => {
4157
const result = utils.fastMerge(testObject, testObjectWithNullishValues, true, false, false);
@@ -97,4 +113,48 @@ describe('fastMerge', () => {
97113

98114
expect(result).toEqual(testObject);
99115
});
116+
117+
it('should add the "ONYX_INTERNALS__REPLACE_OBJECT_MARK" flag to the target object when its source is set to null and "isBatchingMergeChanges" is true', () => {
118+
const result = utils.fastMerge(testMergeChanges[1], testMergeChanges[0], true, true, false);
119+
120+
expect(result).toEqual({
121+
b: {
122+
d: {
123+
h: 'h',
124+
[utils.ONYX_INTERNALS__REPLACE_OBJECT_MARK]: true,
125+
},
126+
h: 'h',
127+
},
128+
});
129+
});
130+
131+
it('should completely replace the target object with its source when the source has the "ONYX_INTERNALS__REPLACE_OBJECT_MARK" flag and "shouldReplaceMarkedObjects" is true', () => {
132+
const result = utils.fastMerge(
133+
testObject,
134+
{
135+
b: {
136+
d: {
137+
h: 'h',
138+
[utils.ONYX_INTERNALS__REPLACE_OBJECT_MARK]: true,
139+
},
140+
h: 'h',
141+
},
142+
},
143+
true,
144+
false,
145+
true,
146+
);
147+
148+
expect(result).toEqual({
149+
a: 'a',
150+
b: {
151+
c: 'c',
152+
d: {
153+
h: 'h',
154+
},
155+
h: 'h',
156+
g: 'g',
157+
},
158+
});
159+
});
100160
});

0 commit comments

Comments
 (0)