@@ -36,6 +36,8 @@ import {
3636 IsIn ,
3737 IsInt ,
3838 IsJSON ,
39+ IsObject ,
40+ IsNotEmptyObject ,
3941 Length ,
4042 IsLowercase ,
4143 IsMongoId ,
@@ -2312,6 +2314,74 @@ describe("IsJSON", function() {
23122314
23132315} ) ;
23142316
2317+ describe ( "IsObject" , function ( ) {
2318+
2319+ const validValues = [ { "key" : "value" } , { key : "value" } , { } ] ;
2320+ const invalidValues : any [ ] = [ null , undefined , "{ key: \"value\" }" , "{ 'key': 'value' }" , "string" , 1234 , false , "[]" , [ ] , [ { key : "value" } ] ] ;
2321+
2322+ class MyClass {
2323+ @IsObject ( )
2324+ someProperty : object ;
2325+ }
2326+
2327+ it ( "should not fail if validator.validate said that its valid" , function ( done ) {
2328+ checkValidValues ( new MyClass ( ) , validValues , done ) ;
2329+ } ) ;
2330+
2331+ it ( "should fail if validator.validate said that its invalid" , function ( done ) {
2332+ checkInvalidValues ( new MyClass ( ) , invalidValues , done ) ;
2333+ } ) ;
2334+
2335+ it ( "should not fail if method in validator said that its valid" , function ( ) {
2336+ validValues . forEach ( value => validator . isObject ( value ) . should . be . true ) ;
2337+ } ) ;
2338+
2339+ it ( "should fail if method in validator said that its invalid" , function ( ) {
2340+ invalidValues . forEach ( value => validator . isObject ( value ) . should . be . false ) ;
2341+ } ) ;
2342+
2343+ it ( "should return error object with proper data" , function ( done ) {
2344+ const validationType = "isObject" ;
2345+ const message = "someProperty must be an object" ;
2346+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message , done ) ;
2347+ } ) ;
2348+
2349+ } ) ;
2350+
2351+ describe ( "IsNotEmptyObject" , function ( ) {
2352+
2353+ const validValues = [ { "key" : "value" } , { key : "value" } ] ;
2354+ const invalidValues = [ null , undefined , "{ key: \"value\" }" , "{ 'key': 'value' }" , "string" , 1234 , false , { } , [ ] , [ { key : "value" } ] ] ;
2355+
2356+ class MyClass {
2357+ @IsNotEmptyObject ( )
2358+ someProperty : object ;
2359+ }
2360+
2361+ it ( "should not fail if validator.validate said that its valid" , function ( done ) {
2362+ checkValidValues ( new MyClass ( ) , validValues , done ) ;
2363+ } ) ;
2364+
2365+ it ( "should fail if validator.validate said that its invalid" , function ( done ) {
2366+ checkInvalidValues ( new MyClass ( ) , invalidValues , done ) ;
2367+ } ) ;
2368+
2369+ it ( "should not fail if method in validator said that its valid" , function ( ) {
2370+ validValues . forEach ( value => validator . isNotEmptyObject ( value ) . should . be . true ) ;
2371+ } ) ;
2372+
2373+ it ( "should fail if method in validator said that its invalid" , function ( ) {
2374+ invalidValues . forEach ( value => validator . isNotEmptyObject ( value ) . should . be . false ) ;
2375+ } ) ;
2376+
2377+ it ( "should return error object with proper data" , function ( done ) {
2378+ const validationType = "isNotEmptyObject" ;
2379+ const message = "someProperty must be a non-empty object" ;
2380+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message , done ) ;
2381+ } ) ;
2382+
2383+ } ) ;
2384+
23152385describe ( "IsLowercase" , function ( ) {
23162386
23172387 const validValues = [
0 commit comments