1- var _ = require ( 'src/util' )
21var Vue = require ( 'src' )
2+ var nextTick = Vue . nextTick
33
44describe ( 'v-if' , function ( ) {
55
@@ -25,15 +25,15 @@ describe('v-if', function () {
2525 expect ( el . innerHTML ) . toBe ( '' )
2626 expect ( vm . $children . length ) . toBe ( 0 )
2727 vm . test = true
28- _ . nextTick ( function ( ) {
28+ nextTick ( function ( ) {
2929 expect ( el . innerHTML ) . toBe ( '<div><test>A</test></div>' )
3030 expect ( vm . $children . length ) . toBe ( 1 )
3131 vm . test = false
32- _ . nextTick ( function ( ) {
32+ nextTick ( function ( ) {
3333 expect ( el . innerHTML ) . toBe ( '' )
3434 expect ( vm . $children . length ) . toBe ( 0 )
3535 vm . test = true
36- _ . nextTick ( function ( ) {
36+ nextTick ( function ( ) {
3737 expect ( el . innerHTML ) . toBe ( '<div><test>A</test></div>' )
3838 expect ( vm . $children . length ) . toBe ( 1 )
3939 var child = vm . $children [ 0 ]
@@ -54,10 +54,10 @@ describe('v-if', function () {
5454 // lazy instantitation
5555 expect ( el . innerHTML ) . toBe ( '' )
5656 vm . test = true
57- _ . nextTick ( function ( ) {
57+ nextTick ( function ( ) {
5858 expect ( el . innerHTML ) . toBe ( '<p>A</p><p>B</p>' )
5959 vm . test = false
60- _ . nextTick ( function ( ) {
60+ nextTick ( function ( ) {
6161 expect ( el . innerHTML ) . toBe ( '' )
6262 done ( )
6363 } )
@@ -88,13 +88,13 @@ describe('v-if', function () {
8888 expect ( el . innerHTML ) . toBe ( '' )
8989 expect ( vm . $children . length ) . toBe ( 0 )
9090 vm . ok = true
91- _ . nextTick ( function ( ) {
91+ nextTick ( function ( ) {
9292 expect ( el . innerHTML ) . toBe ( '<test>123</test>' )
9393 expect ( vm . $children . length ) . toBe ( 1 )
9494 expect ( attachSpy ) . toHaveBeenCalled ( )
9595 expect ( readySpy ) . toHaveBeenCalled ( )
9696 vm . ok = false
97- _ . nextTick ( function ( ) {
97+ nextTick ( function ( ) {
9898 expect ( detachSpy ) . toHaveBeenCalled ( )
9999 expect ( el . innerHTML ) . toBe ( '' )
100100 expect ( vm . $children . length ) . toBe ( 0 )
@@ -125,23 +125,23 @@ describe('v-if', function () {
125125 expect ( vm . $children . length ) . toBe ( 0 )
126126 // toggle if with lazy instantiation
127127 vm . ok = true
128- _ . nextTick ( function ( ) {
128+ nextTick ( function ( ) {
129129 expect ( el . innerHTML ) . toBe ( '<component>AAA</component>' )
130130 expect ( vm . $children . length ) . toBe ( 1 )
131131 // switch view when if=true
132132 vm . view = 'view-b'
133- _ . nextTick ( function ( ) {
133+ nextTick ( function ( ) {
134134 expect ( el . innerHTML ) . toBe ( '<component>BBB</component>' )
135135 expect ( vm . $children . length ) . toBe ( 1 )
136136 // toggle if when already instantiated
137137 vm . ok = false
138- _ . nextTick ( function ( ) {
138+ nextTick ( function ( ) {
139139 expect ( el . innerHTML ) . toBe ( '' )
140140 expect ( vm . $children . length ) . toBe ( 0 )
141141 // toggle if and switch view at the same time
142142 vm . view = 'view-a'
143143 vm . ok = true
144- _ . nextTick ( function ( ) {
144+ nextTick ( function ( ) {
145145 expect ( el . innerHTML ) . toBe ( '<component>AAA</component>' )
146146 expect ( vm . $children . length ) . toBe ( 1 )
147147 done ( )
@@ -161,7 +161,7 @@ describe('v-if', function () {
161161 } )
162162 expect ( el . innerHTML ) . toBe ( '<div>1</div>' )
163163 vm . a = 2
164- _ . nextTick ( function ( ) {
164+ nextTick ( function ( ) {
165165 expect ( el . innerHTML ) . toBe ( '<div>2</div>' )
166166 done ( )
167167 } )
@@ -196,7 +196,7 @@ describe('v-if', function () {
196196 } )
197197 expect ( attachSpy ) . toHaveBeenCalled ( )
198198 vm . show = false
199- _ . nextTick ( function ( ) {
199+ nextTick ( function ( ) {
200200 expect ( detachSpy ) . toHaveBeenCalled ( )
201201 document . body . removeChild ( el )
202202 done ( )
@@ -244,17 +244,17 @@ describe('v-if', function () {
244244 assertMarkup ( )
245245 expect ( attachSpy . calls . count ( ) ) . toBe ( 2 )
246246 vm . show = false
247- _ . nextTick ( function ( ) {
247+ nextTick ( function ( ) {
248248 assertMarkup ( )
249249 expect ( detachSpy . calls . count ( ) ) . toBe ( 1 )
250250 vm . list . push ( { a : 1 } )
251251 vm . show = true
252- _ . nextTick ( function ( ) {
252+ nextTick ( function ( ) {
253253 assertMarkup ( )
254254 expect ( attachSpy . calls . count ( ) ) . toBe ( 2 + 2 )
255255 vm . list . push ( { a : 2 } )
256256 vm . show = false
257- _ . nextTick ( function ( ) {
257+ nextTick ( function ( ) {
258258 assertMarkup ( )
259259 expect ( attachSpy . calls . count ( ) ) . toBe ( 2 + 2 + 1 )
260260 expect ( detachSpy . calls . count ( ) ) . toBe ( 1 + 3 )
@@ -306,10 +306,10 @@ describe('v-if', function () {
306306 } )
307307 expect ( attachSpy ) . not . toHaveBeenCalled ( )
308308 vm . showInner = true
309- _ . nextTick ( function ( ) {
309+ nextTick ( function ( ) {
310310 expect ( attachSpy . calls . count ( ) ) . toBe ( 1 )
311311 vm . showOuter = false
312- _ . nextTick ( function ( ) {
312+ nextTick ( function ( ) {
313313 expect ( detachSpy . calls . count ( ) ) . toBe ( 1 )
314314 document . body . removeChild ( el )
315315 done ( )
@@ -340,15 +340,15 @@ describe('v-if', function () {
340340 assertMarkup ( )
341341 assertCalls ( 1 , 0 )
342342 vm . show = false
343- _ . nextTick ( function ( ) {
343+ nextTick ( function ( ) {
344344 assertMarkup ( )
345345 assertCalls ( 1 , 1 )
346346 vm . show = true
347- _ . nextTick ( function ( ) {
347+ nextTick ( function ( ) {
348348 assertMarkup ( )
349349 assertCalls ( 2 , 1 )
350350 vm . show = false
351- _ . nextTick ( function ( ) {
351+ nextTick ( function ( ) {
352352 assertMarkup ( )
353353 assertCalls ( 2 , 2 )
354354 document . body . removeChild ( el )
@@ -403,13 +403,35 @@ describe('v-if', function () {
403403 } )
404404 expect ( el . textContent ) . toBe ( 'B' )
405405 vm . test = true
406- _ . nextTick ( function ( ) {
406+ nextTick ( function ( ) {
407407 expect ( el . textContent ) . toBe ( 'A' )
408408 vm . test = false
409- _ . nextTick ( function ( ) {
409+ nextTick ( function ( ) {
410410 expect ( el . textContent ) . toBe ( 'B' )
411411 done ( )
412412 } )
413413 } )
414414 } )
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+ } )
415437} )
0 commit comments