mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Add _.cloneDeep test for objects with lots of circular references.
This commit is contained in:
15
test/test.js
15
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';
|
||||
|
||||
Reference in New Issue
Block a user