File size: 2,046 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
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);
});
});
|