Download react-hook-form/src/__tests__/utils/get.test.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/__tests__/utils/get.test.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/__tests__/utils/get.test.ts
-
curl -L -o get.test.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/__tests__/utils/get.test.ts
2.1 kB
| import get from '../../utils/get'; | |
| describe('get', () => { | |
| it('should get the right data', () => { | |
| const test = { | |
| bill: [1, 2, 3], | |
| luo: [1, 3, { betty: 'test' }], | |
| betty: { test: { test1: [{ test2: 'bill' }] } }, | |
| 'betty.test.test1[0].test1': 'test', | |
| 'dotted.filled': 'content', | |
| 'dotted.empty': '', | |
| }; | |
| expect(get(test, 'bill')).toEqual([1, 2, 3]); | |
| expect(get(test, 'bill[0]')).toEqual(1); | |
| expect(get(test, 'luo[2].betty')).toEqual('test'); | |
| expect(get(test, 'betty.test.test1[0].test2')).toEqual('bill'); | |
| expect(get(test, 'betty.test.test1[0].test1')).toEqual('test'); | |
| expect(get(test, 'betty.test.test1[0].test3')).toEqual(undefined); | |
| expect(get(test, 'dotted.filled')).toEqual(test['dotted.filled']); | |
| expect(get(test, 'dotted.empty')).toEqual(test['dotted.empty']); | |
| expect(get(test, 'dotted.nonexistent', 'default')).toEqual('default'); | |
| }); | |
| it('should get from the flat data', () => { | |
| const test = { | |
| bill: 'test', | |
| }; | |
| expect(get(test, 'bill')).toEqual('test'); | |
| }); | |
| it('should return undefined when provided with empty path', () => { | |
| const test = { | |
| bill: 'test', | |
| }; | |
| expect(get(test, '')).toEqual(undefined); | |
| expect(get(test, undefined)).toEqual(undefined); | |
| expect(get(test, null)).toEqual(undefined); | |
| }); | |
| it('should retrieve values from path containing quotes', () => { | |
| const object = { | |
| 'Im with single quote!': { | |
| _f: { | |
| name: "I'm with single quote!", | |
| mount: true, | |
| required: true, | |
| }, | |
| }, | |
| 'With dobule quote': { | |
| _f: { | |
| name: 'With " dobule quote', | |
| mount: true, | |
| required: true, | |
| }, | |
| }, | |
| }; | |
| expect(get(object, "I'm with single quote!")).toEqual({ | |
| _f: { | |
| name: "I'm with single quote!", | |
| mount: true, | |
| required: true, | |
| }, | |
| }); | |
| expect(get(object, 'With " dobule quote')).toEqual({ | |
| _f: { | |
| name: 'With " dobule quote', | |
| mount: true, | |
| required: true, | |
| }, | |
| }); | |
| }); | |
| }); | |