@@ -282,6 +282,30 @@ describe('vi.spyOn() settings', () => {
282282 expect ( spy2 . mock . calls ) . toEqual ( spy1 . mock . calls )
283283 } )
284284
285+ test ( 'vi.spyOn() when spying on a static getter spy returns the same spy' , ( ) => {
286+ const object = createObject ( )
287+ const spy1 = vi . spyOn ( object , 'static' , 'get' )
288+ const spy2 = vi . spyOn ( object , 'static' , 'get' )
289+ expect ( spy1 ) . toBe ( spy2 )
290+
291+ const _example = object . static
292+ expect ( spy2 ) . toHaveBeenCalledTimes ( 1 )
293+ expect ( spy1 ) . toHaveBeenCalledTimes ( 1 )
294+ expect ( spy2 . mock . calls ) . toEqual ( spy1 . mock . calls )
295+ } )
296+
297+ test ( 'vi.spyOn() when spying on a static setter spy returns the same spy' , ( ) => {
298+ const object = createObject ( )
299+ const spy1 = vi . spyOn ( object , 'static' , 'set' )
300+ const spy2 = vi . spyOn ( object , 'static' , 'set' )
301+ expect ( spy1 ) . toBe ( spy2 )
302+
303+ object . static = 33
304+ expect ( spy2 ) . toHaveBeenCalledTimes ( 1 )
305+ expect ( spy1 ) . toHaveBeenCalledTimes ( 1 )
306+ expect ( spy2 . mock . calls ) . toEqual ( spy1 . mock . calls )
307+ } )
308+
285309 test ( 'vi.spyOn() can spy on multiple class instances without intervention' , ( ) => {
286310 class Example {
287311 method ( ) {
@@ -668,5 +692,6 @@ function createObject() {
668692 set getter ( value : number ) {
669693 getterValue = value
670694 } ,
695+ static : 42 ,
671696 }
672697}
0 commit comments