dependabit / test-utils/src / spyOn
Function: spyOn()
ts
function spyOn<T, K>(obj, method): any;Defined in: packages/test-utils/src/mocks.ts:34
Creates a Vitest spy on an object method.
Type Parameters
| Type Parameter |
|---|
T extends object |
K extends string | number | symbol |
Parameters
| Parameter | Type | Description |
|---|---|---|
obj | T | Object to spy on. |
method | K | Method name to spy on. |
Returns
any
Example
ts
const consoleSpy = spyOn(console, 'log');
console.log('test');
expect(consoleSpy).toHaveBeenCalledWith('test');