Function: spy()
spy<
T>(instanceToSpy):T
Defined in: ts-mockito.ts:47
Wraps a real object so its methods call through to the real implementation by default, while individual methods can still be stubbed with when.
Type Parameters
T
T
Parameters
instanceToSpy
T
the real object instance to spy on
Returns
T
the spied mock; pass it to instance to get an object backed by the real one
Example
const foo = new Foo();
const spiedFoo = spy(foo);
when(spiedFoo.getBar(3)).thenReturn('one');
console.log(foo.getBar(3)); // 'one'
console.log(foo.getBaz()); // calls the real method