1
1
import { config , mount } from '@vue/test-utils'
2
2
import { describe , expect , it } from 'vitest'
3
- import { h , nextTick } from 'vue'
4
- import { MotionPlugin } from '../src'
3
+ import { h , nextTick , ref } from 'vue'
4
+ import { MotionComponent , MotionPlugin } from '../src'
5
5
import MotionGroup from '../src/components/MotionGroup'
6
6
import { intersect } from './utils/intersectionObserver'
7
7
import { getTestComponent , useCompletionFn , waitForMockCalls } from './utils'
@@ -10,8 +10,8 @@ import { getTestComponent, useCompletionFn, waitForMockCalls } from './utils'
10
10
config . global . plugins . push ( MotionPlugin )
11
11
12
12
describe . each ( [
13
- { t : 'directive' , name : '`v-motion` directive' } ,
14
- { t : 'component' , name : '`<Motion>` component' } ,
13
+ { t : 'directive' , name : '`v-motion` directive (shared tests) ' } ,
14
+ { t : 'component' , name : '`<Motion>` component (shared tests) ' } ,
15
15
] ) ( `$name` , async ( { t } ) => {
16
16
const TestComponent = getTestComponent ( t )
17
17
@@ -136,6 +136,36 @@ describe.each([
136
136
} )
137
137
} )
138
138
139
+ describe ( '`<Motion>` component' , async ( ) => {
140
+ it ( '#202 - preserve variant style on rerender' , async ( ) => {
141
+ const counter = ref ( 0 )
142
+
143
+ const wrapper = mount (
144
+ { render : ( ) => h ( MotionComponent , null , ( ) => counter . value ) } ,
145
+ {
146
+ props : {
147
+ initial : { scale : 1 } ,
148
+ enter : { scale : 2 } ,
149
+ duration : 10 ,
150
+ } ,
151
+ } ,
152
+ )
153
+
154
+ const el = wrapper . element as HTMLDivElement
155
+ await nextTick ( )
156
+
157
+ // Renders enter
158
+ expect ( el . style . transform ) . toEqual ( 'scale(2) translateZ(0px)' )
159
+
160
+ // Trigger rerender by updating slot variable
161
+ counter . value ++
162
+ await nextTick ( )
163
+
164
+ // Variant style is preserved after rerender/update
165
+ expect ( el . style . transform ) . toEqual ( 'scale(2) translateZ(0px)' )
166
+ } )
167
+ } )
168
+
139
169
describe ( '`<MotionGroup>` component' , async ( ) => {
140
170
it ( 'child node can overwrite helpers' , async ( ) => {
141
171
const wrapper = mount ( {
0 commit comments