@@ -33,26 +33,86 @@ describe('Instance Scope', function () {
3333
3434 describe ( '$data' , function ( ) {
3535
36- var vm = new Vue ( {
37- props : [ 'c' ] ,
38- data : {
39- a : 1
40- }
41- } )
42-
4336 it ( 'should initialize props' , function ( ) {
37+ var vm = new Vue ( {
38+ props : [ 'c' ] ,
39+ data : {
40+ a : 1
41+ }
42+ } )
4443 expect ( vm . hasOwnProperty ( 'c' ) ) . toBe ( true )
4544 } )
4645
4746 it ( 'replace $data' , function ( ) {
48- vm . c = 3
47+ var vm = new Vue ( {
48+ data : {
49+ a : 1
50+ }
51+ } )
4952 vm . $data = { b : 2 }
5053 // proxy new key
5154 expect ( vm . b ) . toBe ( 2 )
5255 // unproxy old key that's no longer present
5356 expect ( vm . hasOwnProperty ( 'a' ) ) . toBe ( false )
54- // should copy props
57+ } )
58+
59+ it ( 'replace $data and handle props' , function ( ) {
60+ var el = document . createElement ( 'div' )
61+ var vm = new Vue ( {
62+ el : el ,
63+ template : '<test a="{{a}}" b="{{*b}}" c="{{<c}}" d="{{>d}}"></test>' ,
64+ data : {
65+ a : 1 ,
66+ b : 2 ,
67+ c : 3 ,
68+ d : 0
69+ } ,
70+ components : {
71+ test : {
72+ props : [ 'a' , 'b' , 'c' , 'd' ] ,
73+ data : function ( ) {
74+ return {
75+ d : 4
76+ }
77+ }
78+ }
79+ }
80+ } )
81+ var child = vm . _children [ 0 ]
82+ expect ( child . a ) . toBe ( 1 )
83+ expect ( child . b ) . toBe ( 2 )
84+ expect ( child . c ) . toBe ( 3 )
85+ expect ( vm . d ) . toBe ( 4 )
86+ expect ( child . d ) . toBe ( 4 )
87+
88+ // test new data without prop fields:
89+ // should just copy
90+ child . $data = { }
91+ expect ( child . a ) . toBe ( 1 )
92+ expect ( child . b ) . toBe ( 2 )
93+ expect ( child . c ) . toBe ( 3 )
94+ expect ( vm . d ) . toBe ( 4 )
95+ expect ( child . d ) . toBe ( 4 )
96+
97+ // test new data with value:
98+ child . $data = {
99+ a : 2 , // two-way
100+ b : 3 , // one-time
101+ c : 4 , // one-way-down
102+ d : 5 // one-way-up
103+ }
104+ // two-way
105+ expect ( child . a ) . toBe ( 2 )
106+ expect ( vm . a ) . toBe ( 2 )
107+ // one-time
108+ expect ( child . b ) . toBe ( 3 )
109+ expect ( vm . b ) . toBe ( 2 )
110+ // one-way down
111+ expect ( child . c ) . toBe ( 4 )
55112 expect ( vm . c ) . toBe ( 3 )
113+ // one-way up
114+ expect ( vm . d ) . toBe ( 5 )
115+ expect ( child . d ) . toBe ( 5 )
56116 } )
57117
58118 } )
@@ -178,4 +238,4 @@ describe('Instance Scope', function () {
178238
179239 } )
180240
181- } )
241+ } )
0 commit comments