File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ function isValid(data, model) {
1111 return true ;
1212 }
1313
14+ if ( typeof model . func !== 'function' ) {
15+ return false ;
16+ }
17+
1418 return model . func ( data ) ;
1519}
1620
Original file line number Diff line number Diff line change 1+ const valid = require ( '../../lib/validators/func' ) ;
2+
3+
4+
5+ describe ( ' - Function validator' , ( ) => {
6+
7+
8+ it ( 'shall be a function' , ( ) => {
9+ expect ( typeof valid ) . toEqual ( 'function' ) ;
10+ } ) ;
11+
12+ describe ( 'is a valid function' , ( ) => {
13+ const model = { } ;
14+
15+ beforeEach ( function ( ) {
16+ model . func = function ( data ) {
17+ return ! ! data ;
18+ } ;
19+
20+ spyOn ( model , 'func' ) . and . callThrough ( ) ;
21+ } ) ;
22+
23+ it ( 'shall call the function after execution' , ( ) => {
24+ expect ( model . func ) . not . toHaveBeenCalled ( ) ;
25+ valid ( 'null' , model ) ;
26+ expect ( model . func ) . toHaveBeenCalled ( ) ;
27+ } ) ;
28+ } ) ;
29+
30+ describe ( 'is NOT a valid function' , ( ) => {
31+ const model = { } ;
32+
33+ beforeEach ( function ( ) {
34+ model . func = 'invalidData' ;
35+ } ) ;
36+
37+ it ( 'shall return false' , ( ) => {
38+ const result = valid ( 'null' , model ) ;
39+ expect ( result ) . toEqual ( false ) ;
40+ } ) ;
41+ } ) ;
42+ } ) ;
You can’t perform that action at this time.
0 commit comments