@@ -17,6 +17,10 @@ var util = require('util');
1717var Parameter = require ( '..' ) ;
1818var parameter = new Parameter ( ) ;
1919
20+ var parameterWithRootValidate = new Parameter ( {
21+ validateRoot : true ,
22+ } ) ;
23+
2024describe ( 'parameter' , function ( ) {
2125 describe ( 'required' , function ( ) {
2226 it ( 'should required work fine' , function ( ) {
@@ -47,6 +51,18 @@ describe('parameter', function () {
4751 } ) ;
4852
4953 describe ( 'validate' , function ( ) {
54+ it ( 'should throw error when received a non object' , function ( ) {
55+ var value = null ;
56+ var rule = { int : { type : 'int1' , required : false } } ;
57+ let err ;
58+ try {
59+ parameter . validate ( rule , undefined )
60+ } catch ( e ) {
61+ err = e ;
62+ }
63+ should ( err . message ) . equal ( "Cannot read property 'hasOwnProperty' of undefined" ) ;
64+ } ) ;
65+
5066 it ( 'should invalid type throw' , function ( ) {
5167 ( function ( ) {
5268 var value = { int : 1.1 } ;
@@ -662,3 +678,12 @@ describe('parameter', function () {
662678 } ) ;
663679 } ) ;
664680} ) ;
681+
682+
683+ describe ( 'validate with option.validateRoot' , function ( ) {
684+ it ( 'should not pass when received a invalid value' , function ( ) {
685+ var value = null ;
686+ var rule = { int : { type : 'int1' , required : false } } ;
687+ parameterWithRootValidate . validate ( rule , value ) [ 0 ] . message . should . equal ( 'the validated value should be a object' ) ; ;
688+ } ) ;
689+ } ) ;
0 commit comments