File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,12 @@ import { validators } from './validators';
9
9
*/
10
10
export const validate = ( typeName : string , data : any ) : boolean => {
11
11
const validateFn : ValidateFunction | undefined = validators . get ( typeName ) ;
12
- // TODO: ignore validation if no validator or throw ?
13
- if ( ! validateFn ) return data ;
12
+
13
+ if ( ! validateFn ) {
14
+ throw Error ( `Validate function not defined for type [${ typeName } ]` ) ;
15
+ } ;
16
+
17
+
14
18
if ( ! validateFn ( data ) ) {
15
19
console . warn ( validateFn . errors ) ;
16
20
const firstError : DefinedError = ( validateFn . errors as DefinedError [ ] ) [ 0 ] ;
Original file line number Diff line number Diff line change @@ -8,4 +8,9 @@ describe('validate', () => {
8
8
it ( 'should return true for valid objects' , ( ) => {
9
9
expect ( validate ( 'End' , false ) ) . toBeTruthy ( 'Expected function validate to return true for valid objects' ) ;
10
10
} ) ;
11
+
12
+ it ( 'should throws an error if validator not found' , ( ) => {
13
+ expect ( ( ) => validate ( 'ValidatorNotDefined' , { } ) ) . toThrowError ( ) ;
14
+ } ) ;
15
+
11
16
} ) ;
You can’t perform that action at this time.
0 commit comments