Skip to content

Commit

Permalink
Cleanup from last review (#5302)
Browse files Browse the repository at this point in the history
* Cleanup from last review

* Can't use object spread
  • Loading branch information
rickhanlonii authored and cpojer committed Jan 14, 2018
1 parent a0370ad commit c9cf010
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
13 changes: 9 additions & 4 deletions packages/jest-util/src/__tests__/deep_cyclic_copy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ it('handles cyclic dependencies', () => {
it('uses the blacklist to avoid copying properties on the first level', () => {
const obj = {
blacklisted: 41,
blacklisted2: 42,
subObj: {
blacklisted: 42,
blacklisted: 43,
},
};

expect(deepCyclicCopy(obj, {blacklist: new Set(['blacklisted'])})).toEqual({
expect(
deepCyclicCopy(obj, {
blacklist: new Set(['blacklisted', 'blacklisted2']),
}),
).toEqual({
subObj: {
blacklisted: 42,
blacklisted: 43,
},
});
});
Expand Down Expand Up @@ -134,7 +139,7 @@ it('does not keep the prototype of arrays when keepPrototype = false', () => {
this.length = 0;
}();

const copy = deepCyclicCopy(sourceArray);
const copy = deepCyclicCopy(sourceArray, {keepPrototype: false});
expect(Object.getPrototypeOf(copy)).not.toBe(
Object.getPrototypeOf(sourceArray),
);
Expand Down
15 changes: 10 additions & 5 deletions packages/jest-util/src/deep_cyclic_copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ function deepCyclicCopyObject(
}

const descriptor = descriptors[key];

if (typeof descriptor.value !== 'undefined') {
delete options.blacklist;
descriptor.value = deepCyclicCopy(descriptor.value, options, cycles);
descriptor.value = deepCyclicCopy(
descriptor.value,
{blacklist: EMPTY, keepPrototype: options.keepPrototype},
cycles,
);
}

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

for (let i = 0; i < length; i++) {
delete options.blacklist;
newArray[i] = deepCyclicCopy(array[i], options, cycles);
newArray[i] = deepCyclicCopy(
array[i],
{blacklist: EMPTY, keepPrototype: options.keepPrototype},
cycles,
);
}

return newArray;
Expand Down

0 comments on commit c9cf010

Please sign in to comment.