11import { config , mount } from '@vue/test-utils'
22import { 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'
55import MotionGroup from '../src/components/MotionGroup'
66import { intersect } from './utils/intersectionObserver'
77import { getTestComponent , useCompletionFn , waitForMockCalls } from './utils'
@@ -10,8 +10,8 @@ import { getTestComponent, useCompletionFn, waitForMockCalls } from './utils'
1010config . global . plugins . push ( MotionPlugin )
1111
1212describe . 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) ' } ,
1515] ) ( `$name` , async ( { t } ) => {
1616 const TestComponent = getTestComponent ( t )
1717
@@ -136,6 +136,36 @@ describe.each([
136136 } )
137137} )
138138
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+
139169describe ( '`<MotionGroup>` component' , async ( ) => {
140170 it ( 'child node can overwrite helpers' , async ( ) => {
141171 const wrapper = mount ( {
0 commit comments