Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/firebird-ng/src/app/utils/deep-copy.spec.ts is written in an unsupported language. File is not indexed.

0001 import {deepCopy} from "./deep-copy";
0002 
0003 
0004 describe('deepCopy', () => {
0005   it('should perform a deep copy of an array', () => {
0006     const array = [{ x: 1 }, { x: 2 }];
0007     const copiedArray = deepCopy(array);
0008     expect(copiedArray).toEqual(array);
0009     expect(copiedArray).not.toBe(array);
0010     expect(copiedArray[0]).not.toBe(array[0]);
0011   });
0012 
0013   it('should perform a deep copy of a Date object', () => {
0014     const date = new Date();
0015     const copiedDate = deepCopy(date);
0016     expect(copiedDate).toEqual(date);
0017     expect(copiedDate).not.toBe(date);
0018   });
0019 
0020   it('should perform a deep copy of an object', () => {
0021     const object = { a: { b: 2 }, c: 3 };
0022     const copiedObject = deepCopy(object);
0023     expect(copiedObject).toEqual(object);
0024     expect(copiedObject).not.toBe(object);
0025     expect(copiedObject.a).not.toBe(object.a);
0026   });
0027 
0028   it('should return primitive types directly', () => {
0029     const num = 42;
0030     const copiedNum = deepCopy(num);
0031     expect(copiedNum).toBe(num);
0032   });
0033 
0034   it('should handle null and undefined correctly', () => {
0035     expect(deepCopy(null)).toBeNull();
0036     expect(deepCopy(undefined)).toBeUndefined();
0037   });
0038 
0039   it('should copy complex objects with nested structures', () => {
0040     const complexObject = { a: { b: { c: 1 } }, d: [2, 3], e: new Date() };
0041     const copiedComplexObject = deepCopy(complexObject);
0042     expect(copiedComplexObject).toEqual(complexObject);
0043     expect(copiedComplexObject.a).not.toBe(complexObject.a);
0044     expect(copiedComplexObject.a.b).not.toBe(complexObject.a.b);
0045     expect(copiedComplexObject.d).not.toBe(complexObject.d);
0046     expect(copiedComplexObject.e).toEqual(complexObject.e);
0047     expect(copiedComplexObject.e).not.toBe(complexObject.e);
0048   });
0049 });