Skip to content

Commit 7de1219

Browse files
committed
test: add test to try to reproduce issue #38
1 parent 6f79ed1 commit 7de1219

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

test/vitest-when.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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
})

0 commit comments

Comments
 (0)