Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/vitest-when.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ describe('vitest-when', () => {
expect(spy()).toEqual(100)
})

it('should fall back to original implementation when using vi.spyOn', () => {
const calculator = {
multiplyByTwo(n: number) {
return 2 * n;
}
}

const spy = vi.spyOn(calculator, 'multiplyByTwo');

expect(spy(2)).toEqual(4)

subject.when(spy).calledWith(1).thenReturn(4)
expect(spy(1)).toEqual(4)
expect(spy(2)).toEqual(4)
})

it('should fall back to original implementation after reset', () => {
const spy = vi.fn((n) => 2 * n)

Expand Down