Skip to content

Commit 7c58153

Browse files
committed
test: add failing test when using vi.spyOn
1 parent 6f79ed1 commit 7c58153

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/vitest-when.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ describe('vitest-when', () => {
6060
expect(spy()).toEqual(100)
6161
})
6262

63+
it('should fall back to original implementation when using a vi.spyOn', () => {
64+
const calculator = {
65+
multiplyByTwo(n: number) {
66+
return 2 * n;
67+
}
68+
}
69+
70+
const spy = vi.spyOn(calculator, 'multiplyByTwo');
71+
72+
expect(spy(2)).toEqual(4)
73+
74+
subject.when(spy).calledWith(1).thenReturn(4)
75+
expect(spy(1)).toEqual(4)
76+
expect(spy(2)).toEqual(4)
77+
})
78+
6379
it('should fall back to original implementation after reset', () => {
6480
const spy = vi.fn((n) => 2 * n)
6581

0 commit comments

Comments
 (0)