1
- var _ = require ( 'src/util' )
2
1
var Vue = require ( 'src' )
2
+ var nextTick = Vue . nextTick
3
3
4
4
describe ( 'v-if' , function ( ) {
5
5
@@ -25,15 +25,15 @@ describe('v-if', function () {
25
25
expect ( el . innerHTML ) . toBe ( '' )
26
26
expect ( vm . $children . length ) . toBe ( 0 )
27
27
vm . test = true
28
- _ . nextTick ( function ( ) {
28
+ nextTick ( function ( ) {
29
29
expect ( el . innerHTML ) . toBe ( '<div><test>A</test></div>' )
30
30
expect ( vm . $children . length ) . toBe ( 1 )
31
31
vm . test = false
32
- _ . nextTick ( function ( ) {
32
+ nextTick ( function ( ) {
33
33
expect ( el . innerHTML ) . toBe ( '' )
34
34
expect ( vm . $children . length ) . toBe ( 0 )
35
35
vm . test = true
36
- _ . nextTick ( function ( ) {
36
+ nextTick ( function ( ) {
37
37
expect ( el . innerHTML ) . toBe ( '<div><test>A</test></div>' )
38
38
expect ( vm . $children . length ) . toBe ( 1 )
39
39
var child = vm . $children [ 0 ]
@@ -54,10 +54,10 @@ describe('v-if', function () {
54
54
// lazy instantitation
55
55
expect ( el . innerHTML ) . toBe ( '' )
56
56
vm . test = true
57
- _ . nextTick ( function ( ) {
57
+ nextTick ( function ( ) {
58
58
expect ( el . innerHTML ) . toBe ( '<p>A</p><p>B</p>' )
59
59
vm . test = false
60
- _ . nextTick ( function ( ) {
60
+ nextTick ( function ( ) {
61
61
expect ( el . innerHTML ) . toBe ( '' )
62
62
done ( )
63
63
} )
@@ -88,13 +88,13 @@ describe('v-if', function () {
88
88
expect ( el . innerHTML ) . toBe ( '' )
89
89
expect ( vm . $children . length ) . toBe ( 0 )
90
90
vm . ok = true
91
- _ . nextTick ( function ( ) {
91
+ nextTick ( function ( ) {
92
92
expect ( el . innerHTML ) . toBe ( '<test>123</test>' )
93
93
expect ( vm . $children . length ) . toBe ( 1 )
94
94
expect ( attachSpy ) . toHaveBeenCalled ( )
95
95
expect ( readySpy ) . toHaveBeenCalled ( )
96
96
vm . ok = false
97
- _ . nextTick ( function ( ) {
97
+ nextTick ( function ( ) {
98
98
expect ( detachSpy ) . toHaveBeenCalled ( )
99
99
expect ( el . innerHTML ) . toBe ( '' )
100
100
expect ( vm . $children . length ) . toBe ( 0 )
@@ -125,23 +125,23 @@ describe('v-if', function () {
125
125
expect ( vm . $children . length ) . toBe ( 0 )
126
126
// toggle if with lazy instantiation
127
127
vm . ok = true
128
- _ . nextTick ( function ( ) {
128
+ nextTick ( function ( ) {
129
129
expect ( el . innerHTML ) . toBe ( '<component>AAA</component>' )
130
130
expect ( vm . $children . length ) . toBe ( 1 )
131
131
// switch view when if=true
132
132
vm . view = 'view-b'
133
- _ . nextTick ( function ( ) {
133
+ nextTick ( function ( ) {
134
134
expect ( el . innerHTML ) . toBe ( '<component>BBB</component>' )
135
135
expect ( vm . $children . length ) . toBe ( 1 )
136
136
// toggle if when already instantiated
137
137
vm . ok = false
138
- _ . nextTick ( function ( ) {
138
+ nextTick ( function ( ) {
139
139
expect ( el . innerHTML ) . toBe ( '' )
140
140
expect ( vm . $children . length ) . toBe ( 0 )
141
141
// toggle if and switch view at the same time
142
142
vm . view = 'view-a'
143
143
vm . ok = true
144
- _ . nextTick ( function ( ) {
144
+ nextTick ( function ( ) {
145
145
expect ( el . innerHTML ) . toBe ( '<component>AAA</component>' )
146
146
expect ( vm . $children . length ) . toBe ( 1 )
147
147
done ( )
@@ -161,7 +161,7 @@ describe('v-if', function () {
161
161
} )
162
162
expect ( el . innerHTML ) . toBe ( '<div>1</div>' )
163
163
vm . a = 2
164
- _ . nextTick ( function ( ) {
164
+ nextTick ( function ( ) {
165
165
expect ( el . innerHTML ) . toBe ( '<div>2</div>' )
166
166
done ( )
167
167
} )
@@ -196,7 +196,7 @@ describe('v-if', function () {
196
196
} )
197
197
expect ( attachSpy ) . toHaveBeenCalled ( )
198
198
vm . show = false
199
- _ . nextTick ( function ( ) {
199
+ nextTick ( function ( ) {
200
200
expect ( detachSpy ) . toHaveBeenCalled ( )
201
201
document . body . removeChild ( el )
202
202
done ( )
@@ -244,17 +244,17 @@ describe('v-if', function () {
244
244
assertMarkup ( )
245
245
expect ( attachSpy . calls . count ( ) ) . toBe ( 2 )
246
246
vm . show = false
247
- _ . nextTick ( function ( ) {
247
+ nextTick ( function ( ) {
248
248
assertMarkup ( )
249
249
expect ( detachSpy . calls . count ( ) ) . toBe ( 1 )
250
250
vm . list . push ( { a : 1 } )
251
251
vm . show = true
252
- _ . nextTick ( function ( ) {
252
+ nextTick ( function ( ) {
253
253
assertMarkup ( )
254
254
expect ( attachSpy . calls . count ( ) ) . toBe ( 2 + 2 )
255
255
vm . list . push ( { a : 2 } )
256
256
vm . show = false
257
- _ . nextTick ( function ( ) {
257
+ nextTick ( function ( ) {
258
258
assertMarkup ( )
259
259
expect ( attachSpy . calls . count ( ) ) . toBe ( 2 + 2 + 1 )
260
260
expect ( detachSpy . calls . count ( ) ) . toBe ( 1 + 3 )
@@ -306,10 +306,10 @@ describe('v-if', function () {
306
306
} )
307
307
expect ( attachSpy ) . not . toHaveBeenCalled ( )
308
308
vm . showInner = true
309
- _ . nextTick ( function ( ) {
309
+ nextTick ( function ( ) {
310
310
expect ( attachSpy . calls . count ( ) ) . toBe ( 1 )
311
311
vm . showOuter = false
312
- _ . nextTick ( function ( ) {
312
+ nextTick ( function ( ) {
313
313
expect ( detachSpy . calls . count ( ) ) . toBe ( 1 )
314
314
document . body . removeChild ( el )
315
315
done ( )
@@ -340,15 +340,15 @@ describe('v-if', function () {
340
340
assertMarkup ( )
341
341
assertCalls ( 1 , 0 )
342
342
vm . show = false
343
- _ . nextTick ( function ( ) {
343
+ nextTick ( function ( ) {
344
344
assertMarkup ( )
345
345
assertCalls ( 1 , 1 )
346
346
vm . show = true
347
- _ . nextTick ( function ( ) {
347
+ nextTick ( function ( ) {
348
348
assertMarkup ( )
349
349
assertCalls ( 2 , 1 )
350
350
vm . show = false
351
- _ . nextTick ( function ( ) {
351
+ nextTick ( function ( ) {
352
352
assertMarkup ( )
353
353
assertCalls ( 2 , 2 )
354
354
document . body . removeChild ( el )
@@ -403,13 +403,35 @@ describe('v-if', function () {
403
403
} )
404
404
expect ( el . textContent ) . toBe ( 'B' )
405
405
vm . test = true
406
- _ . nextTick ( function ( ) {
406
+ nextTick ( function ( ) {
407
407
expect ( el . textContent ) . toBe ( 'A' )
408
408
vm . test = false
409
- _ . nextTick ( function ( ) {
409
+ nextTick ( function ( ) {
410
410
expect ( el . textContent ) . toBe ( 'B' )
411
411
done ( )
412
412
} )
413
413
} )
414
414
} )
415
+
416
+ it ( 'else block teardown' , function ( done ) {
417
+ var created = jasmine . createSpy ( )
418
+ var destroyed = jasmine . createSpy ( )
419
+ var vm = new Vue ( {
420
+ el : el ,
421
+ data : { ok : false } ,
422
+ template : '<div v-if="ok"></div><div v-else><test></test></div>' ,
423
+ components : {
424
+ test : {
425
+ created : created ,
426
+ destroyed : destroyed
427
+ }
428
+ }
429
+ } )
430
+ expect ( created . calls . count ( ) ) . toBe ( 1 )
431
+ vm . $destroy ( )
432
+ nextTick ( function ( ) {
433
+ expect ( destroyed . calls . count ( ) ) . toBe ( 1 )
434
+ done ( )
435
+ } )
436
+ } )
415
437
} )
0 commit comments