From e754a63e99309458d3de3b22cceff9a53e2b30b7 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 14 Aug 2021 10:23:19 +0800 Subject: [PATCH] test: add failed test for #498 (#638) --- test/v3/runtime-core/apiWatch.spec.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/v3/runtime-core/apiWatch.spec.ts b/test/v3/runtime-core/apiWatch.spec.ts index 6fde5b24..d1f440a1 100644 --- a/test/v3/runtime-core/apiWatch.spec.ts +++ b/test/v3/runtime-core/apiWatch.spec.ts @@ -532,6 +532,28 @@ describe('api: watch', () => { expect(data2.value).toMatchObject([1]) }) + // #498 + it('watchEffect should not lead to infinite loop when accessing', async () => { + let dummy = 0 + + const state = reactive({ + data: [], + watchVar: 123, + }) + + watchEffect(() => { + // accessing + state.watchVar + // setting + state.data = [] + dummy += 1 + }) + + expect(dummy).toBe(1) + await nextTick() + expect(dummy).toBe(1) + }) + it('watching deep ref', async () => { const count = ref(0) const double = computed(() => count.value * 2)