Download react-hook-form/src/__tests__/logic/hasPromiseValidation.test.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-hook-form/src/__tests__/logic/hasPromiseValidation.test.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-hook-form/src/__tests__/logic/hasPromiseValidation.test.ts
-
curl -L -o hasPromiseValidation.test.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-hook-form/src/__tests__/logic/hasPromiseValidation.test.ts
2.05 kB
| import hasPromiseValidation from '../../logic/hasPromiseValidation'; | |
| const commonParam = { | |
| mount: true, | |
| name: 'test1', | |
| ref: { | |
| name: 'test1', | |
| value: '', | |
| }, | |
| }; | |
| describe('hasPromiseValidation', () => { | |
| it('validate option does not exist', () => { | |
| expect(hasPromiseValidation(commonParam)).toEqual(false); | |
| }); | |
| it('should return true when validate option has a function type value and is an async function', () => { | |
| const param = { | |
| ...commonParam, | |
| validate: async () => { | |
| return true; | |
| }, | |
| }; | |
| expect(hasPromiseValidation(param)).toEqual(true); | |
| }); | |
| it('should return false when validate option has a function type value and is not an async function', () => { | |
| const param = { | |
| ...commonParam, | |
| validate: () => { | |
| return true; | |
| }, | |
| }; | |
| expect(hasPromiseValidation(param)).toEqual(false); | |
| }); | |
| it('should return true when validate option has an object type value, and the values of all properties are async function.', () => { | |
| const param = { | |
| ...commonParam, | |
| validate: { | |
| positive: async (v: string) => parseInt(v) > 0, | |
| lessThanTen: async (v: string) => parseInt(v) < 10, | |
| }, | |
| }; | |
| expect(hasPromiseValidation(param)).toEqual(true); | |
| }); | |
| it('should return true when validate option has an object type value, and the value of one property is an async function.', () => { | |
| const param = { | |
| ...commonParam, | |
| validate: { | |
| positive: (v: string) => parseInt(v) > 0, | |
| lessThanTen: async (v: string) => parseInt(v) < 10, | |
| }, | |
| }; | |
| expect(hasPromiseValidation(param)).toEqual(true); | |
| }); | |
| it('should return false when validate option has an object type value, and the values of all properties are not async function.', () => { | |
| const param = { | |
| ...commonParam, | |
| validate: { | |
| positive: (v: string) => parseInt(v) > 0, | |
| lessThanTen: (v: string) => parseInt(v) < 10, | |
| }, | |
| }; | |
| expect(hasPromiseValidation(param)).toEqual(false); | |
| }); | |
| }); | |