mirror of https://github.com/vuejs/core.git
chore: format
This commit is contained in:
parent
d96883cf7d
commit
d82fa611e8
|
@ -51,6 +51,7 @@ describe('reactivity/reactive/Array', () => {
|
||||||
const raw = {}
|
const raw = {}
|
||||||
const arr = reactive([{}, {}])
|
const arr = reactive([{}, {}])
|
||||||
arr.push(raw)
|
arr.push(raw)
|
||||||
|
|
||||||
expect(arr.indexOf(raw)).toBe(2)
|
expect(arr.indexOf(raw)).toBe(2)
|
||||||
expect(arr.indexOf(raw, 3)).toBe(-1)
|
expect(arr.indexOf(raw, 3)).toBe(-1)
|
||||||
expect(arr.includes(raw)).toBe(true)
|
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
|
// 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
|
const identityMethods = ['includes', 'indexOf', 'lastIndexOf'] as const
|
||||||
|
|
||||||
function instrumentArr(rawTarget: any[]) {
|
function instrumentArr(rawTarget: any[]) {
|
||||||
identityMethods.forEach(key => {
|
identityMethods.forEach(key => {
|
||||||
const spy = vi.fn(rawTarget[key] as any)
|
const spy = vi.fn(rawTarget[key] as any)
|
||||||
rawTarget[key] = spy
|
rawTarget[key] = spy
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchValue(target: any[], ...args: unknown[]) {
|
function searchValue(target: any[], ...args: unknown[]) {
|
||||||
return identityMethods.map(key => (target[key] as any)(...args))
|
return identityMethods.map(key => (target[key] as any)(...args))
|
||||||
}
|
}
|
||||||
|
|
||||||
function unInstrumentArr(rawTarget: any[]) {
|
function unInstrumentArr(rawTarget: any[]) {
|
||||||
identityMethods.forEach(key => {
|
identityMethods.forEach(key => {
|
||||||
;(rawTarget[key] as any).mockClear()
|
;(rawTarget[key] as any).mockClear()
|
||||||
|
@ -108,6 +112,7 @@ describe('reactivity/reactive/Array', () => {
|
||||||
rawTarget[key] = Array.prototype[key] as any
|
rawTarget[key] = Array.prototype[key] as any
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function expectHaveBeenCalledTimes(rawTarget: any[], times: number) {
|
function expectHaveBeenCalledTimes(rawTarget: any[], times: number) {
|
||||||
identityMethods.forEach(key => {
|
identityMethods.forEach(key => {
|
||||||
expect(rawTarget[key]).toHaveBeenCalledTimes(times)
|
expect(rawTarget[key]).toHaveBeenCalledTimes(times)
|
||||||
|
|
Loading…
Reference in New Issue