Skip to content

Instantly share code, notes, and snippets.

@SeanSobey
Created September 15, 2017 06:44
Show Gist options
  • Save SeanSobey/524121586142ee29d54f8b24cf3c36ac to your computer and use it in GitHub Desktop.
Save SeanSobey/524121586142ee29d54f8b24cf3c36ac to your computer and use it in GitHub Desktop.
Dynamic spy object factory for Jasmine.
export function createSpyObjFactory<T>(ctor: new (...args: Array<any>) => T, includeProto?: boolean, ...args: Array<string>): () => jasmine.SpyObj<T> {
return () => includeProto
? jasmine.createSpyObj<T>(ctor.name, Object.getOwnPropertyNames(ctor.prototype).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(ctor).prototype)).concat(args))
: jasmine.createSpyObj<T>(ctor.name, Object.getOwnPropertyNames(ctor.prototype).concat(args));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment