@@ -293,7 +293,7 @@ describe('prop', function () {
293
293
} )
294
294
295
295
describe ( 'assertions' , function ( ) {
296
- function makeInstance ( value , type , validator , coerce ) {
296
+ function makeInstance ( value , type , validator , coerce , required ) {
297
297
return new Vue ( {
298
298
el : document . createElement ( 'div' ) ,
299
299
template : '<test :test="val"></test>' ,
@@ -306,7 +306,8 @@ describe('prop', function () {
306
306
test : {
307
307
type : type ,
308
308
validator : validator ,
309
- coerce : coerce
309
+ coerce : coerce ,
310
+ required : required
310
311
}
311
312
}
312
313
}
@@ -415,6 +416,22 @@ describe('prop', function () {
415
416
} )
416
417
expect ( hasWarned ( 'Missing required prop' ) ) . toBe ( true )
417
418
} )
419
+
420
+ it ( 'optional with type + null/undefined' , function ( ) {
421
+ makeInstance ( undefined , String )
422
+ expect ( getWarnCount ( ) ) . toBe ( 0 )
423
+ makeInstance ( null , String )
424
+ expect ( getWarnCount ( ) ) . toBe ( 0 )
425
+ } )
426
+
427
+ it ( 'required with type + null/undefined' , function ( ) {
428
+ makeInstance ( undefined , String , null , null , true )
429
+ expect ( getWarnCount ( ) ) . toBe ( 1 )
430
+ expect ( hasWarned ( 'Expected String' ) ) . toBe ( true )
431
+ makeInstance ( null , Boolean , null , null , true )
432
+ expect ( getWarnCount ( ) ) . toBe ( 2 )
433
+ expect ( hasWarned ( 'Expected Boolean' ) ) . toBe ( true )
434
+ } )
418
435
} )
419
436
420
437
it ( 'alternative syntax' , function ( ) {
0 commit comments