@@ -19,13 +19,20 @@ function mount(
19
19
withKeepAlive = false
20
20
) {
21
21
const root = nodeOps . createElement ( 'div' )
22
- render (
23
- h ( BaseTransition , props , ( ) => {
24
- return withKeepAlive ? h ( KeepAlive , null , slot ( ) ) : slot ( )
25
- } ) ,
26
- root
27
- )
28
- return root
22
+ const show = ref ( true )
23
+ const unmount = ( ) => ( show . value = false )
24
+ const App = {
25
+ render ( ) {
26
+ return show . value
27
+ ? h ( BaseTransition , props , ( ) => {
28
+ return withKeepAlive ? h ( KeepAlive , null , slot ( ) ) : slot ( )
29
+ } )
30
+ : null
31
+ }
32
+ }
33
+ render ( h ( App ) , root )
34
+
35
+ return { root, unmount }
29
36
}
30
37
31
38
function mockProps ( extra : BaseTransitionProps = { } , withKeepAlive = false ) {
@@ -258,7 +265,7 @@ describe('BaseTransition', () => {
258
265
) {
259
266
const toggle = ref ( true )
260
267
const { props, cbs } = mockProps ( { mode } )
261
- const root = mount ( props , ( ) =>
268
+ const { root } = mount ( props , ( ) =>
262
269
toggle . value ? trueBranch ( ) : falseBranch ( )
263
270
)
264
271
@@ -347,7 +354,7 @@ describe('BaseTransition', () => {
347
354
} : ToggleOptions ) {
348
355
const toggle = ref ( false )
349
356
const { props, cbs } = mockProps ( )
350
- const root = mount ( props , ( ) =>
357
+ const { root } = mount ( props , ( ) =>
351
358
toggle . value ? trueBranch ( ) : falseBranch ( )
352
359
)
353
360
@@ -431,7 +438,7 @@ describe('BaseTransition', () => {
431
438
) {
432
439
const toggle = ref ( true )
433
440
const { props, cbs } = mockProps ( { } , withKeepAlive )
434
- const root = mount (
441
+ const { root } = mount (
435
442
props ,
436
443
( ) => ( toggle . value ? trueBranch ( ) : falseBranch ( ) ) ,
437
444
withKeepAlive
@@ -537,7 +544,7 @@ describe('BaseTransition', () => {
537
544
) {
538
545
const toggle = ref ( true )
539
546
const { props, cbs } = mockProps ( { } , withKeepAlive )
540
- const root = mount (
547
+ const { root } = mount (
541
548
props ,
542
549
( ) => ( toggle . value ? trueBranch ( ) : falseBranch ( ) ) ,
543
550
withKeepAlive
@@ -670,7 +677,7 @@ describe('BaseTransition', () => {
670
677
) {
671
678
const toggle = ref ( true )
672
679
const { props, cbs } = mockProps ( { mode : 'out-in' } , withKeepAlive )
673
- const root = mount (
680
+ const { root } = mount (
674
681
props ,
675
682
( ) => ( toggle . value ? trueBranch ( ) : falseBranch ( ) ) ,
676
683
withKeepAlive
@@ -763,14 +770,97 @@ describe('BaseTransition', () => {
763
770
} )
764
771
} )
765
772
773
+
774
+ // #6835
775
+ describe ( 'mode: "out-in" toggle again after unmounted' , ( ) => {
776
+ async function testOutIn (
777
+ {
778
+ trueBranch,
779
+ falseBranch,
780
+ trueSerialized,
781
+ falseSerialized
782
+ } : ToggleOptions ,
783
+ withKeepAlive = false
784
+ ) {
785
+ const toggle = ref ( true )
786
+ const { props, cbs } = mockProps ( { mode : 'out-in' } , withKeepAlive )
787
+ const { root, unmount } = mount (
788
+ props ,
789
+ ( ) => ( toggle . value ? trueBranch ( ) : falseBranch ( ) ) ,
790
+ withKeepAlive
791
+ )
792
+
793
+ // trigger toggle
794
+ toggle . value = false
795
+ await nextTick ( )
796
+ // a placeholder is injected until the leave finishes
797
+ expect ( serializeInner ( root ) ) . toBe ( `${ trueSerialized } <!---->` )
798
+ expect ( props . onBeforeLeave ) . toHaveBeenCalledTimes ( 1 )
799
+ assertCalledWithEl ( props . onBeforeLeave , trueSerialized )
800
+ expect ( props . onLeave ) . toHaveBeenCalledTimes ( 1 )
801
+ assertCalledWithEl ( props . onLeave , trueSerialized )
802
+ expect ( props . onAfterLeave ) . not . toHaveBeenCalled ( )
803
+ // enter should not have started
804
+ expect ( props . onBeforeEnter ) . not . toHaveBeenCalled ( )
805
+ expect ( props . onEnter ) . not . toHaveBeenCalled ( )
806
+ expect ( props . onAfterEnter ) . not . toHaveBeenCalled ( )
807
+
808
+ cbs . doneLeave [ trueSerialized ] ( )
809
+ expect ( props . onAfterLeave ) . toHaveBeenCalledTimes ( 1 )
810
+ assertCalledWithEl ( props . onAfterLeave , trueSerialized )
811
+ // have to wait for a tick because this triggers an update
812
+ await nextTick ( )
813
+ expect ( serializeInner ( root ) ) . toBe ( falseSerialized )
814
+ // enter should start
815
+ expect ( props . onBeforeEnter ) . toHaveBeenCalledTimes ( 1 )
816
+ assertCalledWithEl ( props . onBeforeEnter , falseSerialized )
817
+ expect ( props . onEnter ) . toHaveBeenCalledTimes ( 1 )
818
+ assertCalledWithEl ( props . onEnter , falseSerialized )
819
+ expect ( props . onAfterEnter ) . not . toHaveBeenCalled ( )
820
+ // finish enter
821
+ cbs . doneEnter [ falseSerialized ] ( )
822
+ expect ( props . onAfterEnter ) . toHaveBeenCalledTimes ( 1 )
823
+ assertCalledWithEl ( props . onAfterEnter , falseSerialized )
824
+
825
+ unmount ( )
826
+ // toggle again after unmounted should not throw error
827
+ toggle . value = true
828
+ await nextTick ( )
829
+ expect ( serializeInner ( root ) ) . toBe ( `<!---->` )
830
+
831
+ assertCalls ( props , {
832
+ onBeforeEnter : 1 ,
833
+ onEnter : 1 ,
834
+ onAfterEnter : 1 ,
835
+ onEnterCancelled : 0 ,
836
+ onBeforeLeave : 1 ,
837
+ onLeave : 1 ,
838
+ onAfterLeave : 1 ,
839
+ onLeaveCancelled : 0
840
+ } )
841
+ }
842
+
843
+ test ( 'w/ elements' , async ( ) => {
844
+ await runTestWithElements ( testOutIn )
845
+ } )
846
+
847
+ test ( 'w/ components' , async ( ) => {
848
+ await runTestWithComponents ( testOutIn )
849
+ } )
850
+
851
+ test ( 'w/ KeepAlive' , async ( ) => {
852
+ await runTestWithKeepAlive ( testOutIn )
853
+ } )
854
+ } )
855
+
766
856
describe ( 'mode: "out-in" toggle before finish' , ( ) => {
767
857
async function testOutInBeforeFinish (
768
858
{ trueBranch, falseBranch, trueSerialized } : ToggleOptions ,
769
859
withKeepAlive = false
770
860
) {
771
861
const toggle = ref ( true )
772
862
const { props, cbs } = mockProps ( { mode : 'out-in' } , withKeepAlive )
773
- const root = mount (
863
+ const { root } = mount (
774
864
props ,
775
865
( ) => ( toggle . value ? trueBranch ( ) : falseBranch ( ) ) ,
776
866
withKeepAlive
@@ -847,7 +937,7 @@ describe('BaseTransition', () => {
847
937
) {
848
938
const toggle = ref ( true )
849
939
const { props, cbs } = mockProps ( { mode : 'out-in' } , withKeepAlive )
850
- const root = mount (
940
+ const { root } = mount (
851
941
props ,
852
942
( ) => ( toggle . value ? trueBranch ( ) : falseBranch ( ) ) ,
853
943
withKeepAlive
@@ -925,7 +1015,7 @@ describe('BaseTransition', () => {
925
1015
) {
926
1016
const toggle = ref ( true )
927
1017
const { props, cbs } = mockProps ( { mode : 'in-out' } , withKeepAlive )
928
- const root = mount (
1018
+ const { root } = mount (
929
1019
props ,
930
1020
( ) => ( toggle . value ? trueBranch ( ) : falseBranch ( ) ) ,
931
1021
withKeepAlive
@@ -1029,7 +1119,7 @@ describe('BaseTransition', () => {
1029
1119
) {
1030
1120
const toggle = ref ( true )
1031
1121
const { props, cbs } = mockProps ( { mode : 'in-out' } , withKeepAlive )
1032
- const root = mount (
1122
+ const { root } = mount (
1033
1123
props ,
1034
1124
( ) => ( toggle . value ? trueBranch ( ) : falseBranch ( ) ) ,
1035
1125
withKeepAlive
0 commit comments