From c9cf0101fe7f1347007209bd3870a1635ba66901 Mon Sep 17 00:00:00 2001 From: Rick Hanlon II Date: Sun, 14 Jan 2018 06:53:55 -0500 Subject: [PATCH] Cleanup from last review (#5302) * Cleanup from last review * Can't use object spread --- .../src/__tests__/deep_cyclic_copy.test.js | 13 +++++++++---- packages/jest-util/src/deep_cyclic_copy.js | 15 ++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/jest-util/src/__tests__/deep_cyclic_copy.test.js b/packages/jest-util/src/__tests__/deep_cyclic_copy.test.js index 8de6d5a4772f..ab9acb234d9f 100644 --- a/packages/jest-util/src/__tests__/deep_cyclic_copy.test.js +++ b/packages/jest-util/src/__tests__/deep_cyclic_copy.test.js @@ -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, }, }); }); @@ -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), ); diff --git a/packages/jest-util/src/deep_cyclic_copy.js b/packages/jest-util/src/deep_cyclic_copy.js index f6e6f02c8dd5..7c08cb82f9ea 100644 --- a/packages/jest-util/src/deep_cyclic_copy.js +++ b/packages/jest-util/src/deep_cyclic_copy.js @@ -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; @@ -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;