From: Evan You Date: Fri, 14 Aug 2020 21:35:49 +0000 (-0400) Subject: test(watch): add same value skipping trigger test X-Git-Tag: v3.0.0-rc.6~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=223f18052944c57f449cb29ec6ea7c8c796c6e3d;p=thirdparty%2Fvuejs%2Fcore.git test(watch): add same value skipping trigger test --- diff --git a/packages/runtime-core/__tests__/apiWatch.spec.ts b/packages/runtime-core/__tests__/apiWatch.spec.ts index edeedf6c2a..76812390f8 100644 --- a/packages/runtime-core/__tests__/apiWatch.spec.ts +++ b/packages/runtime-core/__tests__/apiWatch.spec.ts @@ -77,6 +77,21 @@ describe('api: watch', () => { expect(spy).toBeCalledWith([1], expect.anything(), expect.anything()) }) + it('should not fire if watched getter result did not change', async () => { + const spy = jest.fn() + const n = ref(0) + watch(() => n.value % 2, spy) + + n.value++ + await nextTick() + expect(spy).toBeCalledTimes(1) + + n.value += 2 + await nextTick() + // should not be called again because getter result did not change + expect(spy).toBeCalledTimes(1) + }) + it('watching single source: computed ref', async () => { const count = ref(0) const plus = computed(() => count.value + 1)