File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
test/unit/specs/directives Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,10 @@ exports._initData = function () {
5454 if ( optionsData ) {
5555 this . _data = optionsData
5656 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+ ) {
5861 optionsData . $set ( prop , propsData [ prop ] )
5962 }
6063 }
Original file line number Diff line number Diff line change @@ -442,6 +442,37 @@ if (_.inBrowser) {
442442 } )
443443 expect ( vm . $children [ 0 ] . prop ) . toBe ( true )
444444 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+ } ) )
445476 } )
446477 } )
447478}
You can’t perform that action at this time.
0 commit comments