File tree 2 files changed +35
-1
lines changed
test/unit/specs/directives
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,10 @@ exports._initData = function () {
54
54
if ( optionsData ) {
55
55
this . _data = optionsData
56
56
for ( var prop in propsData ) {
57
- if ( this . _props [ prop ] . raw !== null ) {
57
+ if (
58
+ this . _props [ prop ] . raw !== null ||
59
+ ! optionsData . hasOwnProperty ( prop )
60
+ ) {
58
61
optionsData . $set ( prop , propsData [ prop ] )
59
62
}
60
63
}
Original file line number Diff line number Diff line change @@ -442,6 +442,37 @@ if (_.inBrowser) {
442
442
} )
443
443
expect ( vm . $children [ 0 ] . prop ) . toBe ( true )
444
444
expect ( vm . $el . textContent ) . toBe ( 'true' )
445
+ expect ( JSON . stringify ( vm . $children [ 0 ] . $data ) ) . toBe ( JSON . stringify ( {
446
+ prop : true
447
+ } ) )
448
+ } )
449
+
450
+ it ( 'should initialize with default value when not provided & has default data' , function ( ) {
451
+ var vm = new Vue ( {
452
+ el : el ,
453
+ template : '<test></test>' ,
454
+ components : {
455
+ test : {
456
+ props : {
457
+ prop : {
458
+ type : String ,
459
+ default : 'hello'
460
+ }
461
+ } ,
462
+ data : function ( ) {
463
+ return {
464
+ other : 'world'
465
+ }
466
+ } ,
467
+ template : '{{prop}} {{other}}'
468
+ }
469
+ }
470
+ } )
471
+ expect ( vm . $el . textContent ) . toBe ( 'hello world' )
472
+ expect ( JSON . stringify ( vm . $children [ 0 ] . $data ) ) . toBe ( JSON . stringify ( {
473
+ other : 'world' ,
474
+ prop : 'hello'
475
+ } ) )
445
476
} )
446
477
} )
447
478
}
You can’t perform that action at this time.
0 commit comments