Download react-hook-form/src/__tests__/utils/deepEqual.test.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 3.01 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/__tests__/utils/deepEqual.test.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/__tests__/utils/deepEqual.test.ts
-
curl -L -o deepEqual.test.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/__tests__/utils/deepEqual.test.ts
3.01 kB
| import deepEqual from '../../utils/deepEqual'; | |
| describe('deepEqual', () => { | |
| it('should return false when two sets not match', () => { | |
| expect( | |
| deepEqual([{ test: '123' }, { test: '455' }, { test: '455' }], []), | |
| ).toBeFalsy(); | |
| expect( | |
| deepEqual( | |
| [{ test: '123' }, { test: '455' }, { test: '455' }], | |
| [{ test: '123' }, { test: '455' }, { test: '455', test1: 'what' }], | |
| ), | |
| ).toBeFalsy(); | |
| expect(deepEqual([{}], [])).toBeFalsy(); | |
| expect(deepEqual([], [{}])).toBeFalsy(); | |
| expect(deepEqual(new Date(), new Date('1999'))).toBeFalsy(); | |
| expect( | |
| deepEqual( | |
| { | |
| unknown: undefined, | |
| userName: '', | |
| fruit: '', | |
| }, | |
| { | |
| userName: '', | |
| fruit: '', | |
| break: {}, | |
| }, | |
| ), | |
| ).toBeFalsy(); | |
| }); | |
| it('should return false when either type is primitive', () => { | |
| expect(deepEqual(null, [])).toBeFalsy(); | |
| expect(deepEqual([], null)).toBeFalsy(); | |
| expect(deepEqual({}, undefined)).toBeFalsy(); | |
| expect(deepEqual(undefined, {})).toBeFalsy(); | |
| }); | |
| it('should return true when two sets matches', () => { | |
| expect( | |
| deepEqual([{ name: 'useFieldArray' }], [{ name: 'useFieldArray' }]), | |
| ).toBeTruthy(); | |
| expect( | |
| deepEqual( | |
| [{ test: '123' }, { test: '455' }, { test: '455' }], | |
| [{ test: '123' }, { test: '455' }, { test: '455' }], | |
| ), | |
| ).toBeTruthy(); | |
| expect(deepEqual({}, {})).toBeTruthy(); | |
| expect(deepEqual([], [])).toBeTruthy(); | |
| expect( | |
| deepEqual( | |
| [{ test: '123' }, { test: '455' }], | |
| [{ test: '123' }, { test: '455' }], | |
| ), | |
| ).toBeTruthy(); | |
| expect( | |
| deepEqual( | |
| [ | |
| { | |
| test: '123', | |
| nestedArray: [{ test: '123' }, { test: '455' }, { test: '455' }], | |
| }, | |
| { | |
| test: '455', | |
| nestedArray: [{ test: '123' }, { test: '455' }, { test: '455' }], | |
| }, | |
| ], | |
| [ | |
| { | |
| test: '123', | |
| nestedArray: [{ test: '123' }, { test: '455' }, { test: '455' }], | |
| }, | |
| { | |
| test: '455', | |
| nestedArray: [{ test: '123' }, { test: '455' }, { test: '455' }], | |
| }, | |
| ], | |
| ), | |
| ).toBeTruthy(); | |
| }); | |
| it('should compare date time object valueOf', () => { | |
| expect( | |
| deepEqual({ test: new Date('1990') }, { test: new Date('1990') }), | |
| ).toBeTruthy(); | |
| }); | |
| it('should be capable of comparing objects with circular references', () => { | |
| const a: any = { test: '123' }; | |
| const b: any = { test: '123' }; | |
| a.self = a; | |
| b.self = b; | |
| expect(deepEqual(a, b)).toBeTruthy(); | |
| a.other = { test: '123' }; | |
| b.other = { test: '456' }; | |
| expect(deepEqual(a, b)).toBeFalsy(); | |
| b.other.test = '123'; | |
| a.other.parent = b; | |
| b.other.parent = a; | |
| expect(deepEqual(a, b)).toBeTruthy(); | |
| b.other.parent = a.other; | |
| expect(deepEqual(a, b)).toBeFalsy(); | |
| }); | |
| }); | |