@@ -184,6 +184,7 @@ import {
184
184
isUUID ,
185
185
isUppercase ,
186
186
isVariableWidth ,
187
+ length ,
187
188
matches ,
188
189
max ,
189
190
maxDate ,
@@ -318,7 +319,7 @@ describe('IsDefined', () => {
318
319
it ( 'should return error object with proper data' , ( ) => {
319
320
const validationType = 'isDefined' ;
320
321
const message = 'someProperty should not be null or undefined' ;
321
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
322
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
322
323
} ) ;
323
324
} ) ;
324
325
@@ -1780,7 +1781,7 @@ describe('IsEthereumAddress', () => {
1780
1781
it ( 'should return error object with proper data' , ( ) => {
1781
1782
const validationType = 'isEthereumAddress' ;
1782
1783
const message = 'someProperty must be an Ethereum address' ;
1783
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1784
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1784
1785
} ) ;
1785
1786
} ) ;
1786
1787
@@ -1813,7 +1814,7 @@ describe('IsBtcAddress', () => {
1813
1814
it ( 'should return error object with proper data' , ( ) => {
1814
1815
const validationType = 'isBtcAddress' ;
1815
1816
const message = 'someProperty must be a BTC address' ;
1816
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1817
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1817
1818
} ) ;
1818
1819
} ) ;
1819
1820
@@ -1846,7 +1847,7 @@ describe('IsDataURI', () => {
1846
1847
it ( 'should return error object with proper data' , ( ) => {
1847
1848
const validationType = 'isDataURI' ;
1848
1849
const message = 'someProperty must be a data uri format' ;
1849
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1850
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1850
1851
} ) ;
1851
1852
} ) ;
1852
1853
@@ -1879,7 +1880,7 @@ describe('IsHSL', () => {
1879
1880
it ( 'should return error object with proper data' , ( ) => {
1880
1881
const validationType = 'isHSL' ;
1881
1882
const message = 'someProperty must be a HSL color' ;
1882
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1883
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1883
1884
} ) ;
1884
1885
} ) ;
1885
1886
@@ -1912,7 +1913,7 @@ describe('IsRgbColor', () => {
1912
1913
it ( 'should return error object with proper data' , ( ) => {
1913
1914
const validationType = 'isRgbColor' ;
1914
1915
const message = 'someProperty must be RGB color' ;
1915
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1916
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1916
1917
} ) ;
1917
1918
} ) ;
1918
1919
@@ -1945,7 +1946,7 @@ describe('IsIdentityCard', () => {
1945
1946
it ( 'should return error object with proper data' , ( ) => {
1946
1947
const validationType = 'isIdentityCard' ;
1947
1948
const message = 'someProperty must be a identity card number' ;
1948
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1949
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1949
1950
} ) ;
1950
1951
} ) ;
1951
1952
@@ -1978,7 +1979,7 @@ describe('IsEAN', () => {
1978
1979
it ( 'should return error object with proper data' , ( ) => {
1979
1980
const validationType = 'isEAN' ;
1980
1981
const message = 'someProperty must be an EAN (European Article Number)' ;
1981
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1982
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1982
1983
} ) ;
1983
1984
} ) ;
1984
1985
@@ -2011,7 +2012,7 @@ describe('IsISRC', () => {
2011
2012
it ( 'should return error object with proper data' , ( ) => {
2012
2013
const validationType = 'isISRC' ;
2013
2014
const message = 'someProperty must be an ISRC' ;
2014
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
2015
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
2015
2016
} ) ;
2016
2017
} ) ;
2017
2018
@@ -2044,7 +2045,7 @@ describe('IsRFC3339', () => {
2044
2045
it ( 'should return error object with proper data' , ( ) => {
2045
2046
const validationType = 'isRFC3339' ;
2046
2047
const message = 'someProperty must be RFC 3339 date' ;
2047
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
2048
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
2048
2049
} ) ;
2049
2050
} ) ;
2050
2051
@@ -2077,7 +2078,7 @@ describe('IsLocale', () => {
2077
2078
it ( 'should return error object with proper data' , ( ) => {
2078
2079
const validationType = 'isLocale' ;
2079
2080
const message = 'someProperty must be locale' ;
2080
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
2081
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
2081
2082
} ) ;
2082
2083
} ) ;
2083
2084
@@ -2114,7 +2115,7 @@ describe('IsMagnetURI', () => {
2114
2115
it ( 'should return error object with proper data' , ( ) => {
2115
2116
const validationType = 'isMagnetURI' ;
2116
2117
const message = 'someProperty must be magnet uri format' ;
2117
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
2118
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
2118
2119
} ) ;
2119
2120
} ) ;
2120
2121
@@ -2147,7 +2148,7 @@ describe('IsMimeType', () => {
2147
2148
it ( 'should return error object with proper data' , ( ) => {
2148
2149
const validationType = 'isMimeType' ;
2149
2150
const message = 'someProperty must be MIME type format' ;
2150
- return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
2151
+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
2151
2152
} ) ;
2152
2153
} ) ;
2153
2154
@@ -3195,61 +3196,81 @@ describe('IsNotEmptyObject', () => {
3195
3196
[ ] ,
3196
3197
[ { key : 'value' } ] ,
3197
3198
] ;
3198
- const nullableValidValues = [ { key : 'value' } , { key : 'value' } ] ;
3199
- const nullableInvalidValues = [
3200
- null ,
3201
- undefined ,
3202
- '{ key: "value" }' ,
3203
- "{ 'key': 'value' }" ,
3204
- 'string' ,
3205
- 1234 ,
3206
- false ,
3207
- { } ,
3208
- { key : undefined } ,
3209
- { key : null } ,
3210
- [ ] ,
3211
- [ { key : 'value' } ] ,
3212
- ] ;
3213
3199
3214
3200
class MyClass {
3215
3201
@IsNotEmptyObject ( )
3216
3202
someProperty : object ;
3217
3203
}
3218
3204
3219
- class NullableMyClass {
3220
- @IsNotEmptyObject ( { nullable : true } )
3221
- someProperty : object ;
3222
- }
3223
-
3224
- it . each ( [
3225
- [ new MyClass ( ) , validValues ] ,
3226
- [ new NullableMyClass ( ) , nullableValidValues ] ,
3227
- ] ) ( 'should not fail if validator.validate said that its valid' , ( validationObject , values ) => {
3228
- return checkValidValues ( validationObject , values ) ;
3205
+ it ( 'should not fail if validator.validate said that its valid' , ( ) => {
3206
+ return checkValidValues ( new MyClass ( ) , validValues ) ;
3229
3207
} ) ;
3230
3208
3231
- it . each ( [
3232
- [ new MyClass ( ) , invalidValues ] ,
3233
- [ new NullableMyClass ( ) , nullableInvalidValues ] ,
3234
- ] ) ( 'should fail if validator.validate said that its invalid' , ( validationObject , values ) => {
3235
- return checkInvalidValues ( validationObject , values ) ;
3209
+ it ( 'should fail if validator.validate said that its invalid' , ( ) => {
3210
+ return checkInvalidValues ( new MyClass ( ) , invalidValues ) ;
3236
3211
} ) ;
3237
3212
3238
3213
it ( 'should not fail if method in validator said that its valid' , ( ) => {
3239
3214
validValues . forEach ( value => expect ( isNotEmptyObject ( value ) ) . toBeTruthy ( ) ) ;
3240
- nullableValidValues . forEach ( value => expect ( isNotEmptyObject ( value , { nullable : true } ) ) . toBeTruthy ( ) ) ;
3241
3215
} ) ;
3242
3216
3243
3217
it ( 'should fail if method in validator said that its invalid' , ( ) => {
3244
3218
invalidValues . forEach ( value => expect ( isNotEmptyObject ( value ) ) . toBeFalsy ( ) ) ;
3245
- nullableInvalidValues . forEach ( value => expect ( isNotEmptyObject ( value , { nullable : true } ) ) . toBeFalsy ( ) ) ;
3246
3219
} ) ;
3247
3220
3248
3221
it ( 'should return error object with proper data' , ( ) => {
3249
3222
const validationType = 'isNotEmptyObject' ;
3250
3223
const message = 'someProperty must be a non-empty object' ;
3251
3224
return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
3252
3225
} ) ;
3226
+
3227
+ describe ( 'with `nullable` option' , ( ) => {
3228
+ const nullableValidValues = validValues ;
3229
+ const nullableInvalidValues = invalidValues ;
3230
+ const nonNullableValidValues = [ { key : 'value' } , { key : 'value' } ] ;
3231
+ const nonNullableInvalidValues = [
3232
+ null ,
3233
+ undefined ,
3234
+ '{ key: "value" }' ,
3235
+ "{ 'key': 'value' }" ,
3236
+ 'string' ,
3237
+ 1234 ,
3238
+ false ,
3239
+ { } ,
3240
+ { key : undefined } ,
3241
+ { key : null } ,
3242
+ [ ] ,
3243
+ [ { key : 'value' } ] ,
3244
+ ] ;
3245
+ class NullableMyClass {
3246
+ @IsNotEmptyObject ( { nullable : true } )
3247
+ someProperty : object ;
3248
+ }
3249
+ class NonNullableMyClass {
3250
+ @IsNotEmptyObject ( { nullable : false } )
3251
+ someProperty : object ;
3252
+ }
3253
+
3254
+ it ( 'should not fail if validator.validate said that its valid' , async ( ) => {
3255
+ await checkValidValues ( new NullableMyClass ( ) , nullableValidValues ) ;
3256
+ await checkValidValues ( new NonNullableMyClass ( ) , nonNullableValidValues ) ;
3257
+ } ) ;
3258
+
3259
+ it ( 'should fail if validator.validate said that its valid' , async ( ) => {
3260
+ await checkInvalidValues ( new NullableMyClass ( ) , nullableInvalidValues ) ;
3261
+ await checkInvalidValues ( new NonNullableMyClass ( ) , nonNullableInvalidValues ) ;
3262
+ } ) ;
3263
+
3264
+ it ( 'should not fail if method in validator said that its valid' , ( ) => {
3265
+ nullableValidValues . forEach ( value => expect ( isNotEmptyObject ( value , { nullable : true } ) ) . toBeTruthy ( ) ) ;
3266
+ nonNullableValidValues . forEach ( value => expect ( isNotEmptyObject ( value , { nullable : false } ) ) . toBeTruthy ( ) ) ;
3267
+ } ) ;
3268
+
3269
+ it ( 'should fail if method in validator said that its invalid' , ( ) => {
3270
+ nullableInvalidValues . forEach ( value => expect ( isNotEmptyObject ( value , { nullable : true } ) ) . toBeFalsy ( ) ) ;
3271
+ nonNullableInvalidValues . forEach ( value => expect ( isNotEmptyObject ( value , { nullable : false } ) ) . toBeFalsy ( ) ) ;
3272
+ } ) ;
3273
+ } ) ;
3253
3274
} ) ;
3254
3275
3255
3276
describe ( 'IsLowercase' , ( ) => {
@@ -3979,10 +4000,6 @@ describe('IsTimeZone', () => {
3979
4000
describe ( 'isPhoneNumber' , ( ) => {
3980
4001
describe ( 'with region' , ( ) => {
3981
4002
const validValues = [
3982
- '0311111111' ,
3983
- '031 633 60 01' ,
3984
- '079 4 666 666' ,
3985
- '075 416 20 30' ,
3986
4003
'+41 311111111' ,
3987
4004
'+41 31 633 60 01' ,
3988
4005
'+41 79 4 666 666' ,
@@ -3991,7 +4008,6 @@ describe('isPhoneNumber', () => {
3991
4008
'+41 (0)31 633 60 01' ,
3992
4009
'+41 (0)79 4 666 666' ,
3993
4010
'+41 (0)75 416 20 30' ,
3994
- '+49 9072 1111' ,
3995
4011
] ;
3996
4012
const invalidValues = [ undefined , null , 'asdf' , '1' ] ;
3997
4013
0 commit comments