@@ -1089,12 +1089,11 @@ export class ModuleMocker {
1089
1089
methodKey : K ,
1090
1090
) : V extends ClassLike | FunctionLike ? Spied < V > : never ;
1091
1091
1092
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1093
- spyOn < T extends object , K extends PropertyLikeKeys < T > > (
1092
+ spyOn < T extends object > (
1094
1093
object : T ,
1095
- methodKey : K ,
1094
+ methodKey : keyof T ,
1096
1095
accessType ?: 'get' | 'set' ,
1097
- ) {
1096
+ ) : MockInstance {
1098
1097
if ( typeof object !== 'object' && typeof object !== 'function' ) {
1099
1098
throw new Error (
1100
1099
`Cannot spyOn on a primitive value; ${ this . _typeOf ( object ) } given` ,
@@ -1168,16 +1167,16 @@ export class ModuleMocker {
1168
1167
} ) ;
1169
1168
}
1170
1169
1171
- return object [ methodKey ] ;
1170
+ return object [ methodKey ] as Mock ;
1172
1171
}
1173
1172
1174
- private _spyOnProperty < T extends object , K extends PropertyLikeKeys < T > > (
1175
- obj : T ,
1176
- propertyKey : K ,
1173
+ private _spyOnProperty < T extends object > (
1174
+ object : T ,
1175
+ propertyKey : keyof T ,
1177
1176
accessType : 'get' | 'set' ,
1178
- ) : Mock < ( ) => T > {
1179
- let descriptor = Object . getOwnPropertyDescriptor ( obj , propertyKey ) ;
1180
- let proto = Object . getPrototypeOf ( obj ) ;
1177
+ ) : MockInstance {
1178
+ let descriptor = Object . getOwnPropertyDescriptor ( object , propertyKey ) ;
1179
+ let proto = Object . getPrototypeOf ( object ) ;
1181
1180
1182
1181
while ( ! descriptor && proto !== null ) {
1183
1182
descriptor = Object . getOwnPropertyDescriptor ( proto , propertyKey ) ;
@@ -1216,19 +1215,19 @@ export class ModuleMocker {
1216
1215
descriptor [ accessType ] = this . _makeComponent ( { type : 'function' } , ( ) => {
1217
1216
// @ts -expect-error: mock is assignable
1218
1217
descriptor ! [ accessType ] = original ;
1219
- Object . defineProperty ( obj , propertyKey , descriptor ! ) ;
1218
+ Object . defineProperty ( object , propertyKey , descriptor ! ) ;
1220
1219
} ) ;
1221
1220
1222
- ( descriptor [ accessType ] as Mock < ( ) => T > ) . mockImplementation ( function (
1221
+ ( descriptor [ accessType ] as Mock ) . mockImplementation ( function (
1223
1222
this : unknown ,
1224
1223
) {
1225
1224
// @ts -expect-error - wrong context
1226
1225
return original . apply ( this , arguments ) ;
1227
1226
} ) ;
1228
1227
}
1229
1228
1230
- Object . defineProperty ( obj , propertyKey , descriptor ) ;
1231
- return descriptor [ accessType ] as Mock < ( ) => T > ;
1229
+ Object . defineProperty ( object , propertyKey , descriptor ) ;
1230
+ return descriptor [ accessType ] as Mock ;
1232
1231
}
1233
1232
1234
1233
clearAllMocks ( ) : void {
0 commit comments