diff options
Diffstat (limited to 'spec/frontend/lib/utils/common_utils_spec.js')
-rw-r--r-- | spec/frontend/lib/utils/common_utils_spec.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/common_utils_spec.js b/spec/frontend/lib/utils/common_utils_spec.js index 444d4a96f9c..8697249ebf5 100644 --- a/spec/frontend/lib/utils/common_utils_spec.js +++ b/spec/frontend/lib/utils/common_utils_spec.js @@ -1174,4 +1174,43 @@ describe('common_utils', () => { }); }); }); + + describe('cloneWithoutReferences', () => { + it('clones the provided object', () => { + const obj = { + foo: 'bar', + cool: 1337, + nested: { + peanut: 'butter', + }, + arrays: [0, 1, 2], + }; + + const cloned = commonUtils.cloneWithoutReferences(obj); + + expect(cloned).toMatchObject({ + foo: 'bar', + cool: 1337, + nested: { + peanut: 'butter', + }, + arrays: [0, 1, 2], + }); + }); + + it('does not persist object references after cloning', () => { + const ref = { + foo: 'bar', + }; + + const obj = { + ref, + }; + + const cloned = commonUtils.cloneWithoutReferences(obj); + + expect(cloned.ref).toMatchObject({ foo: 'bar' }); + expect(cloned.ref === ref).toBe(false); + }); + }); }); |