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';
99 */
1010export const validate = ( typeName : string , data : any ) : boolean => {
1111 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+
1418 if ( ! validateFn ( data ) ) {
1519 console . warn ( validateFn . errors ) ;
1620 const firstError : DefinedError = ( validateFn . errors as DefinedError [ ] ) [ 0 ] ;
Original file line number Diff line number Diff line change @@ -8,4 +8,9 @@ describe('validate', () => {
88 it ( 'should return true for valid objects' , ( ) => {
99 expect ( validate ( 'End' , false ) ) . toBeTruthy ( 'Expected function validate to return true for valid objects' ) ;
1010 } ) ;
11+
12+ it ( 'should throws an error if validator not found' , ( ) => {
13+ expect ( ( ) => validate ( 'ValidatorNotDefined' , { } ) ) . toThrowError ( ) ;
14+ } ) ;
15+
1116} ) ;
You can’t perform that action at this time.
0 commit comments