Skip to content

Commit 223f180

Browse files
committed
test(watch): add same value skipping trigger test
1 parent 517c2b8 commit 223f180

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/runtime-core/__tests__/apiWatch.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ describe('api: watch', () => {
7777
expect(spy).toBeCalledWith([1], expect.anything(), expect.anything())
7878
})
7979

80+
it('should not fire if watched getter result did not change', async () => {
81+
const spy = jest.fn()
82+
const n = ref(0)
83+
watch(() => n.value % 2, spy)
84+
85+
n.value++
86+
await nextTick()
87+
expect(spy).toBeCalledTimes(1)
88+
89+
n.value += 2
90+
await nextTick()
91+
// should not be called again because getter result did not change
92+
expect(spy).toBeCalledTimes(1)
93+
})
94+
8095
it('watching single source: computed ref', async () => {
8196
const count = ref(0)
8297
const plus = computed(() => count.value + 1)

0 commit comments

Comments
 (0)