File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -313,4 +313,25 @@ describe('vitest-when', () => {
313313 expect ( spy ( ...callArgs ) ) . toBe ( 'success' )
314314 } ,
315315 )
316+
317+ it ( 'can spy on an async method' , async ( ) => {
318+ const target = {
319+ // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
320+ async resolveOrganizationSetting ( options ) : Promise < string [ ] > {
321+ throw new Error ( 'unimplemented' )
322+ } ,
323+ }
324+
325+ vi . spyOn ( target , 'resolveOrganizationSetting' )
326+
327+ subject
328+ // eslint-disable-next-line @typescript-eslint/unbound-method
329+ . when ( target . resolveOrganizationSetting )
330+ . calledWith ( { path : 'test' } )
331+ . thenResolve ( [ 'value' ] )
332+
333+ const result = await target . resolveOrganizationSetting ( { path : 'test' } )
334+
335+ expect ( result ) . toEqual ( [ 'value' ] )
336+ } )
316337} )
You can’t perform that action at this time.
0 commit comments