@@ -6,6 +6,7 @@ import { nextFrame } from 'web/runtime/transition-util'
6
6
if ( ! isIE9 ) {
7
7
describe ( 'Transition basic' , ( ) => {
8
8
const { duration, buffer } = injectStyles ( )
9
+ const explicitDuration = 100
9
10
10
11
let el
11
12
beforeEach ( ( ) => {
@@ -875,5 +876,232 @@ if (!isIE9) {
875
876
} ) . $mount ( )
876
877
expect ( `<transition> can only be used on a single element` ) . toHaveBeenWarned ( )
877
878
} )
879
+
880
+ it ( 'explicit transition total duration' , done => {
881
+ const vm = new Vue ( {
882
+ template : `
883
+ <div>
884
+ <transition :duration="${ explicitDuration } ">
885
+ <div v-if="ok" class="test">foo</div>
886
+ </transition>
887
+ </div>
888
+ ` ,
889
+ data : { ok : true }
890
+ } ) . $mount ( el )
891
+
892
+ vm . ok = false
893
+
894
+ waitForUpdate ( ( ) => {
895
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave v-leave-active' )
896
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
897
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
898
+ } ) . thenWaitFor ( explicitDuration - buffer ) . then ( ( ) => {
899
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
900
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
901
+ expect ( vm . $el . children . length ) . toBe ( 0 )
902
+ vm . ok = true
903
+ } ) . then ( ( ) => {
904
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter v-enter-active' )
905
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
906
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
907
+ } ) . thenWaitFor ( explicitDuration - buffer ) . then ( ( ) => {
908
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
909
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
910
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test' )
911
+ } ) . then ( done )
912
+ } )
913
+
914
+ it ( 'explicit transition enter duration and auto leave duration' , done => {
915
+ const vm = new Vue ( {
916
+ template : `
917
+ <div>
918
+ <transition :duration="{ enter: ${ explicitDuration } }">
919
+ <div v-if="ok" class="test">foo</div>
920
+ </transition>
921
+ </div>
922
+ ` ,
923
+ data : { ok : true }
924
+ } ) . $mount ( el )
925
+
926
+ vm . ok = false
927
+
928
+ waitForUpdate ( ( ) => {
929
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave v-leave-active' )
930
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
931
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
932
+ } ) . thenWaitFor ( duration - buffer ) . then ( ( ) => {
933
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
934
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
935
+ expect ( vm . $el . children . length ) . toBe ( 0 )
936
+ vm . ok = true
937
+ } ) . then ( ( ) => {
938
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter v-enter-active' )
939
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
940
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
941
+ } ) . thenWaitFor ( explicitDuration - buffer ) . then ( ( ) => {
942
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
943
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
944
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test' )
945
+ } ) . then ( done )
946
+ } )
947
+
948
+ it ( 'explicit transition leave duration and auto enter duration' , done => {
949
+ const vm = new Vue ( {
950
+ template : `
951
+ <div>
952
+ <transition :duration="{ leave: ${ explicitDuration } }">
953
+ <div v-if="ok" class="test">foo</div>
954
+ </transition>
955
+ </div>
956
+ ` ,
957
+ data : { ok : true }
958
+ } ) . $mount ( el )
959
+
960
+ vm . ok = false
961
+
962
+ waitForUpdate ( ( ) => {
963
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave v-leave-active' )
964
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
965
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
966
+ } ) . thenWaitFor ( explicitDuration - buffer ) . then ( ( ) => {
967
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
968
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
969
+ expect ( vm . $el . children . length ) . toBe ( 0 )
970
+ vm . ok = true
971
+ } ) . then ( ( ) => {
972
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter v-enter-active' )
973
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
974
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
975
+ } ) . thenWaitFor ( duration - buffer ) . then ( ( ) => {
976
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
977
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
978
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test' )
979
+ } ) . then ( done )
980
+ } )
981
+
982
+ it ( 'explicit transition separate enter and leave duration' , done => {
983
+ const enter = 100
984
+ const leave = 200
985
+
986
+ const vm = new Vue ( {
987
+ template : `
988
+ <div>
989
+ <transition :duration="{ enter: ${ enter } , leave: ${ leave } }">
990
+ <div v-if="ok" class="test">foo</div>
991
+ </transition>
992
+ </div>
993
+ ` ,
994
+ data : { ok : true }
995
+ } ) . $mount ( el )
996
+
997
+ vm . ok = false
998
+
999
+ waitForUpdate ( ( ) => {
1000
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave v-leave-active' )
1001
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
1002
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
1003
+ } ) . thenWaitFor ( leave - buffer ) . then ( ( ) => {
1004
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
1005
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
1006
+ expect ( vm . $el . children . length ) . toBe ( 0 )
1007
+ vm . ok = true
1008
+ } ) . then ( ( ) => {
1009
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter v-enter-active' )
1010
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
1011
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
1012
+ } ) . thenWaitFor ( enter - buffer ) . then ( ( ) => {
1013
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
1014
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
1015
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test' )
1016
+ } ) . then ( done )
1017
+ } )
1018
+
1019
+ it ( 'explicit transition enter and leave duration + duration change' , done => {
1020
+ const enter1 = 200
1021
+ const enter2 = 100
1022
+ const leave1 = 50
1023
+ const leave2 = 300
1024
+
1025
+ const vm = new Vue ( {
1026
+ template : `
1027
+ <div>
1028
+ <transition :duration="{ enter: enter, leave: leave }">
1029
+ <div v-if="ok" class="test">foo</div>
1030
+ </transition>
1031
+ </div>
1032
+ ` ,
1033
+ data : {
1034
+ ok : true ,
1035
+ enter : enter1 ,
1036
+ leave : leave1
1037
+ }
1038
+ } ) . $mount ( el )
1039
+
1040
+ vm . ok = false
1041
+
1042
+ waitForUpdate ( ( ) => {
1043
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave v-leave-active' )
1044
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
1045
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
1046
+ } ) . thenWaitFor ( leave1 - buffer ) . then ( ( ) => {
1047
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
1048
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
1049
+ expect ( vm . $el . children . length ) . toBe ( 0 )
1050
+ vm . ok = true
1051
+ } ) . then ( ( ) => {
1052
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter v-enter-active' )
1053
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
1054
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
1055
+ } ) . thenWaitFor ( enter1 - buffer ) . then ( ( ) => {
1056
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
1057
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
1058
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test' )
1059
+ vm . enter = enter2
1060
+ vm . leave = leave2
1061
+ } ) . then ( ( ) => {
1062
+ vm . ok = false
1063
+ } ) . then ( ( ) => {
1064
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave v-leave-active' )
1065
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
1066
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
1067
+ } ) . thenWaitFor ( leave2 - buffer ) . then ( ( ) => {
1068
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-leave-active v-leave-to' )
1069
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
1070
+ expect ( vm . $el . children . length ) . toBe ( 0 )
1071
+ vm . ok = true
1072
+ } ) . then ( ( ) => {
1073
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter v-enter-active' )
1074
+ } ) . thenWaitFor ( nextFrame ) . then ( ( ) => {
1075
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
1076
+ } ) . thenWaitFor ( enter2 - buffer ) . then ( ( ) => {
1077
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test v-enter-active v-enter-to' )
1078
+ } ) . thenWaitFor ( buffer * 2 ) . then ( ( ) => {
1079
+ expect ( vm . $el . children [ 0 ] . className ) . toBe ( 'test' )
1080
+ } ) . then ( done )
1081
+ } )
1082
+
1083
+ it ( 'warn invalid explicit durations' , done => {
1084
+ const vm = new Vue ( {
1085
+ template : `
1086
+ <div>
1087
+ <transition :duration="{ enter: NaN, leave: 'foo' }">
1088
+ <div v-if="ok" class="test">foo</div>
1089
+ </transition>
1090
+ </div>
1091
+ ` ,
1092
+ data : {
1093
+ ok : true
1094
+ }
1095
+ } ) . $mount ( el )
1096
+
1097
+ vm . ok = false
1098
+ waitForUpdate ( ( ) => {
1099
+ expect ( `<transition> explicit leave duration is not a valid number - got "foo"` ) . toHaveBeenWarned ( )
1100
+ } ) . thenWaitFor ( duration + buffer ) . then ( ( ) => {
1101
+ vm . ok = true
1102
+ } ) . then ( ( ) => {
1103
+ expect ( `<transition> explicit enter duration is NaN` ) . toHaveBeenWarned ( )
1104
+ } ) . then ( done )
1105
+ } )
878
1106
} )
879
1107
}
0 commit comments