From de01ffb20c43eaedd40c32aaf36d67588dda61a6 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 16 Oct 2019 12:45:38 +0800 Subject: [PATCH] fix(effect): effect function will be called more than one time when Array.prototype.shift be called --- packages/reactivity/__tests__/effect.spec.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/reactivity/__tests__/effect.spec.ts b/packages/reactivity/__tests__/effect.spec.ts index 340bf10931e..96a0eb43347 100644 --- a/packages/reactivity/__tests__/effect.spec.ts +++ b/packages/reactivity/__tests__/effect.spec.ts @@ -156,13 +156,21 @@ describe('reactivity/effect', () => { it('should observe iteration', () => { let dummy const list = reactive(['Hello']) - effect(() => (dummy = list.join(' '))) + const fn = jest.fn(() => (dummy = list.join(' '))) + effect(fn) + + expect(fn).toHaveBeenCalledTimes(1) // normal expect(dummy).toBe('Hello') list.push('World!') expect(dummy).toBe('Hello World!') + + expect(fn).toHaveBeenCalledTimes(2) // normal + list.shift() expect(dummy).toBe('World!') + + expect(fn).toHaveBeenCalledTimes(5) // It depends on list.length }) it('should observe implicit array length changes', () => {