@@ -51,6 +51,7 @@ describe('reactivity/reactive/Array', () => {
51
51
const raw = { }
52
52
const arr = reactive ( [ { } , { } ] )
53
53
arr . push ( raw )
54
+
54
55
expect ( arr . indexOf ( raw ) ) . toBe ( 2 )
55
56
expect ( arr . indexOf ( raw , 3 ) ) . toBe ( - 1 )
56
57
expect ( arr . includes ( raw ) ) . toBe ( true )
@@ -90,24 +91,28 @@ describe('reactivity/reactive/Array', () => {
90
91
} )
91
92
92
93
// only non-existent reactive will try to search by using its raw value
93
- describe ( 'Array identity methods have been called times ' , ( ) => {
94
+ describe ( 'Array identity methods should not be called more than necessary ' , ( ) => {
94
95
const identityMethods = [ 'includes' , 'indexOf' , 'lastIndexOf' ] as const
96
+
95
97
function instrumentArr ( rawTarget : any [ ] ) {
96
98
identityMethods . forEach ( key => {
97
99
const spy = vi . fn ( rawTarget [ key ] as any )
98
100
rawTarget [ key ] = spy
99
101
} )
100
102
}
103
+
101
104
function searchValue ( target : any [ ] , ...args : unknown [ ] ) {
102
105
return identityMethods . map ( key => ( target [ key ] as any ) ( ...args ) )
103
106
}
107
+
104
108
function unInstrumentArr ( rawTarget : any [ ] ) {
105
109
identityMethods . forEach ( key => {
106
110
; ( rawTarget [ key ] as any ) . mockClear ( )
107
111
// relink to prototype method
108
112
rawTarget [ key ] = Array . prototype [ key ] as any
109
113
} )
110
114
}
115
+
111
116
function expectHaveBeenCalledTimes ( rawTarget : any [ ] , times : number ) {
112
117
identityMethods . forEach ( key => {
113
118
expect ( rawTarget [ key ] ) . toHaveBeenCalledTimes ( times )
0 commit comments