From 545f81a23a1c4f23ffb9707eeb40973bf5f053fe Mon Sep 17 00:00:00 2001 From: Alex Jover Date: Sun, 12 Mar 2017 21:01:38 +0100 Subject: [PATCH] Add spyOn function introduced in Jest 19 (#14867) * Add spyOn function introduced in Jest 19 * Update header of jest/index.d.ts file * Fix types of spyOn function * Fix jest.spyOn types --- jest/index.d.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) mode change 100644 => 100755 jest/index.d.ts diff --git a/jest/index.d.ts b/jest/index.d.ts old mode 100644 new mode 100755 index 234583ef3e..595a42ea2b --- a/jest/index.d.ts +++ b/jest/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for Jest 19.2.0 // Project: http://facebook.github.io/jest/ -// Definitions by: Asana , Ivo Stratev , jwbay , Alexey Svetliakov +// Definitions by: Asana , Ivo Stratev , jwbay , Alexey Svetliakov , Alex Jover Morales // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 @@ -77,6 +77,8 @@ declare namespace jest { function runTimersToTime(msToRun: number): typeof jest; /** Explicitly supplies the mock object that the module system should return for the specified module. */ function setMock(moduleName: string, moduleExports: T): typeof jest; + /** Creates a mock function similar to jest.fn but also tracks calls to object[methodName] */ + function spyOn(object: T, method: M): SpyInstance; /** Indicates that the module system should never return a mocked version of the specified module from require() (e.g. that it should always return the real module). */ function unmock(moduleName: string): typeof jest; /** Instructs Jest to use fake versions of the standard timer functions. */ @@ -245,6 +247,10 @@ declare namespace jest { (...args: any[]): any; } + interface SpyInstance extends MockInstance { + mockRestore(): void; + } + /** * Wrap module with mock definitions * @example