Skip to content

Commit e754a63

Browse files
authored
test: add failed test for #498 (#638)
1 parent e67940f commit e754a63

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/v3/runtime-core/apiWatch.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,28 @@ describe('api: watch', () => {
532532
expect(data2.value).toMatchObject([1])
533533
})
534534

535+
// #498
536+
it('watchEffect should not lead to infinite loop when accessing', async () => {
537+
let dummy = 0
538+
539+
const state = reactive({
540+
data: [],
541+
watchVar: 123,
542+
})
543+
544+
watchEffect(() => {
545+
// accessing
546+
state.watchVar
547+
// setting
548+
state.data = []
549+
dummy += 1
550+
})
551+
552+
expect(dummy).toBe(1)
553+
await nextTick()
554+
expect(dummy).toBe(1)
555+
})
556+
535557
it('watching deep ref', async () => {
536558
const count = ref(0)
537559
const double = computed(() => count.value * 2)

0 commit comments

Comments
 (0)