File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -157,4 +157,49 @@ describe('ref', () => {
157
157
} ) . $mount ( )
158
158
expect ( vm . $refs . test ) . toBe ( vm . $children [ 0 ] )
159
159
} )
160
+
161
+ it ( 'should should call callback (v-for)' , done => {
162
+ const vm = new Vue ( {
163
+ data : {
164
+ items : [ 1 , 2 , 3 ]
165
+ } ,
166
+ template : `
167
+ <div>
168
+ <test v-for="n in items" :ref="onRef" :n="n"></test>
169
+ </div>
170
+ ` ,
171
+ components : {
172
+ test : {
173
+ props : [ 'n' ] ,
174
+ template : '<div>{{ n }}</div>'
175
+ }
176
+ } ,
177
+ methods : {
178
+ onRef ( ref , remove ) {
179
+ if ( ! this . $refs . list ) this . $refs . list = [ ]
180
+
181
+ if ( remove ) {
182
+ const index = this . $refs . list . indexOf ( ref )
183
+
184
+ if ( index > - 1 ) this . $refs . list . splice ( index , 1 )
185
+ } else {
186
+ this . $refs . list . push ( ref )
187
+ }
188
+ }
189
+ }
190
+ } ) . $mount ( )
191
+ assertRefs ( )
192
+ // updating
193
+ vm . items . push ( 4 )
194
+ waitForUpdate ( assertRefs )
195
+ . then ( ( ) => { vm . items = [ ] } )
196
+ . then ( assertRefs )
197
+ . then ( done )
198
+
199
+ function assertRefs ( ) {
200
+ expect ( Array . isArray ( vm . $refs . list ) ) . toBe ( true )
201
+ expect ( vm . $refs . list . length ) . toBe ( vm . items . length )
202
+ expect ( vm . $refs . list . every ( ( comp , i ) => comp . $el . textContent === String ( i + 1 ) ) ) . toBe ( true )
203
+ }
204
+ } )
160
205
} )
You can’t perform that action at this time.
0 commit comments