Skip to content

Commit bf0448a

Browse files
committed
chore: add test
1 parent 1c917ef commit bf0448a

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, expect, it, vi } from 'vitest'
2+
import { mount } from '@vue/test-utils'
3+
import { Motion } from '@/components'
4+
import { defineComponent, nextTick, onMounted, ref, watchEffect } from 'vue'
5+
import { useTransform } from '@/value/use-transform'
6+
import { delay } from '@/shared/test'
7+
8+
describe('useTransform', () => {
9+
it('should update when reactive value changes', async () => {
10+
const Component = defineComponent({
11+
setup() {
12+
const x = ref(0)
13+
const transform = useTransform(() => {
14+
return x.value
15+
})
16+
onMounted(() => {
17+
x.value = 100
18+
})
19+
return () => {
20+
return <Motion style={{ x: transform }} />
21+
}
22+
},
23+
})
24+
const wrapper = mount(Component)
25+
await delay(100)
26+
expect(wrapper.html()).toContain('100')
27+
})
28+
})

packages/motion/src/value/use-computed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCombineMotionValues } from '@/value/use-combine-values'
22
import { type MotionValue, collectMotionValues } from 'framer-motion/dom'
3-
import { onBeforeUpdate } from 'vue'
3+
import { watchEffect } from 'vue'
44

55
export function useComputed<T>(computed: () => T): MotionValue<T> {
66
/**
@@ -15,7 +15,7 @@ export function useComputed<T>(computed: () => T): MotionValue<T> {
1515

1616
collectMotionValues.current = undefined
1717

18-
onBeforeUpdate(() => {
18+
watchEffect(() => {
1919
unsubscribe()
2020
collectMotionValues.current = []
2121
updateValue()

0 commit comments

Comments
 (0)