Skip to content

Commit c9cf010

Browse files
rickhanloniicpojer
authored andcommitted
Cleanup from last review (#5302)
* Cleanup from last review * Can't use object spread
1 parent a0370ad commit c9cf010

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

packages/jest-util/src/__tests__/deep_cyclic_copy.test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,19 @@ it('handles cyclic dependencies', () => {
6565
it('uses the blacklist to avoid copying properties on the first level', () => {
6666
const obj = {
6767
blacklisted: 41,
68+
blacklisted2: 42,
6869
subObj: {
69-
blacklisted: 42,
70+
blacklisted: 43,
7071
},
7172
};
7273

73-
expect(deepCyclicCopy(obj, {blacklist: new Set(['blacklisted'])})).toEqual({
74+
expect(
75+
deepCyclicCopy(obj, {
76+
blacklist: new Set(['blacklisted', 'blacklisted2']),
77+
}),
78+
).toEqual({
7479
subObj: {
75-
blacklisted: 42,
80+
blacklisted: 43,
7681
},
7782
});
7883
});
@@ -134,7 +139,7 @@ it('does not keep the prototype of arrays when keepPrototype = false', () => {
134139
this.length = 0;
135140
}();
136141

137-
const copy = deepCyclicCopy(sourceArray);
142+
const copy = deepCyclicCopy(sourceArray, {keepPrototype: false});
138143
expect(Object.getPrototypeOf(copy)).not.toBe(
139144
Object.getPrototypeOf(sourceArray),
140145
);

packages/jest-util/src/deep_cyclic_copy.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ function deepCyclicCopyObject(
6666
}
6767

6868
const descriptor = descriptors[key];
69-
7069
if (typeof descriptor.value !== 'undefined') {
71-
delete options.blacklist;
72-
descriptor.value = deepCyclicCopy(descriptor.value, options, cycles);
70+
descriptor.value = deepCyclicCopy(
71+
descriptor.value,
72+
{blacklist: EMPTY, keepPrototype: options.keepPrototype},
73+
cycles,
74+
);
7375
}
7476

7577
descriptor.configurable = true;
@@ -92,8 +94,11 @@ function deepCyclicCopyArray(
9294
cycles.set(array, newArray);
9395

9496
for (let i = 0; i < length; i++) {
95-
delete options.blacklist;
96-
newArray[i] = deepCyclicCopy(array[i], options, cycles);
97+
newArray[i] = deepCyclicCopy(
98+
array[i],
99+
{blacklist: EMPTY, keepPrototype: options.keepPrototype},
100+
cycles,
101+
);
97102
}
98103

99104
return newArray;

0 commit comments

Comments
 (0)