From bf1bcaf39402a0dfd93984dea75b2eeebcd1c25d Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 6 Oct 2015 08:16:22 -0700 Subject: [PATCH] Add `_.cloneDeep` test for objects with lots of circular references. --- test/test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/test.js b/test/test.js index 1defc17ef..a432271b7 100644 --- a/test/test.js +++ b/test/test.js @@ -2088,6 +2088,21 @@ assert.ok(actual.bar.b === actual.foo.b && actual === actual.foo.b.c.d && actual !== object); }); + QUnit.test('`_.cloneDeep` should deep clone objects with lots of circular references', function(assert) { + assert.expect(2); + + var cyclical = {}; + _.times(LARGE_ARRAY_SIZE + 1, function(index) { + cyclical['v' + index] = [index ? cyclical['v' + (index - 1)] : cyclical]; + }); + + var clone = _.cloneDeep(cyclical), + actual = clone['v' + LARGE_ARRAY_SIZE][0]; + + assert.strictEqual(actual, clone['v' + (LARGE_ARRAY_SIZE - 1)]); + assert.notStrictEqual(actual, cyclical['v' + (LARGE_ARRAY_SIZE - 1)]); + }); + _.each(['clone', 'cloneDeep'], function(methodName) { var func = _[methodName], isDeep = methodName == 'cloneDeep';