Last active
April 21, 2018 10:24
-
-
Save lydemann/67758e852ef1179e85862c890a1de271 to your computer and use it in GitHub Desktop.
Provides helpers for easy and typesafe mocking with spies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This class provides helpers for easy and typesafe mocking with spies | |
*/ | |
// get keys of type | |
export declare function keys<T extends object>(): Array<keyof T>; | |
export class SpyHelper { | |
/* | |
Ensures typesafe creation of a spy object | |
*/ | |
public static createSpyObj<T>(name: string = 'spyObject', methods: Array<keyof T>): jasmine.SpyObj<T> { | |
return jasmine.createSpyObj<T>(name, methods); | |
} | |
public static createSpyObjFromObj<T>(name: string = 'spyObject', obj: T): jasmine.SpyObj<T> { | |
const keysOfObject = []; | |
for (const key in obj) { | |
if (obj.hasOwnProperty(key)) { | |
keysOfObject.push(key); | |
} | |
} | |
return jasmine.createSpyObj<T>(name, keysOfObject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment