( originalImplementation?: T, )
| 242 | } |
| 243 | |
| 244 | export function fn<T extends Procedure | Constructable = Procedure>( |
| 245 | originalImplementation?: T, |
| 246 | ): Mock<T> { |
| 247 | // if the function is already a mock, just return the same function, |
| 248 | // similarly to how vi.spyOn() works |
| 249 | if (originalImplementation != null && isMockFunction(originalImplementation)) { |
| 250 | return originalImplementation as Mock<T> |
| 251 | } |
| 252 | |
| 253 | return createMockInstance({ |
| 254 | // we pass this down so getMockImplementation() always returns the value |
| 255 | mockImplementation: originalImplementation, |
| 256 | // special case so that .mockReset() resets the value to |
| 257 | // the the originalImplementation instead of () => undefined |
| 258 | resetToMockImplementation: true, |
| 259 | }) as Mock<T> |
| 260 | } |
| 261 | |
| 262 | export function spyOn<T extends object, S extends Properties<Required<T>>>( |
| 263 | object: T, |
no test coverage detected