From d82fa611e86d54cf1bedbb8c956b6e9597d4d3b6 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 11 Oct 2024 11:25:48 +0800 Subject: [PATCH] chore: format --- packages/reactivity/__tests__/reactiveArray.spec.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/reactivity/__tests__/reactiveArray.spec.ts b/packages/reactivity/__tests__/reactiveArray.spec.ts index 2760eb8a1a8..a1154cfa248 100644 --- a/packages/reactivity/__tests__/reactiveArray.spec.ts +++ b/packages/reactivity/__tests__/reactiveArray.spec.ts @@ -51,6 +51,7 @@ describe('reactivity/reactive/Array', () => { const raw = {} const arr = reactive([{}, {}]) arr.push(raw) + expect(arr.indexOf(raw)).toBe(2) expect(arr.indexOf(raw, 3)).toBe(-1) expect(arr.includes(raw)).toBe(true) @@ -90,17 +91,20 @@ describe('reactivity/reactive/Array', () => { }) // only non-existent reactive will try to search by using its raw value - describe('Array identity methods have been called times', () => { + describe('Array identity methods should not be called more than necessary', () => { const identityMethods = ['includes', 'indexOf', 'lastIndexOf'] as const + function instrumentArr(rawTarget: any[]) { identityMethods.forEach(key => { const spy = vi.fn(rawTarget[key] as any) rawTarget[key] = spy }) } + function searchValue(target: any[], ...args: unknown[]) { return identityMethods.map(key => (target[key] as any)(...args)) } + function unInstrumentArr(rawTarget: any[]) { identityMethods.forEach(key => { ;(rawTarget[key] as any).mockClear() @@ -108,6 +112,7 @@ describe('reactivity/reactive/Array', () => { rawTarget[key] = Array.prototype[key] as any }) } + function expectHaveBeenCalledTimes(rawTarget: any[], times: number) { identityMethods.forEach(key => { expect(rawTarget[key]).toHaveBeenCalledTimes(times)