mirror of
https://github.com/mapillary/mapillary-js.git
synced 2026-01-25 14:07:28 +00:00
27 lines
841 B
TypeScript
27 lines
841 B
TypeScript
export class MockCreator {
|
|
public create<T>(ctor: new (...args: any[]) => T, name: string): T {
|
|
const spy: { [key: string]: any } = {};
|
|
|
|
for (const key in ctor.prototype) {
|
|
if (!!Object.getOwnPropertyDescriptor(ctor.prototype, key) &&
|
|
!Object.getOwnPropertyDescriptor(ctor.prototype, key).get) {
|
|
spy[key] = jasmine.createSpy(name + "." + key, ctor.prototype[key]);
|
|
}
|
|
}
|
|
|
|
return <T>spy;
|
|
}
|
|
|
|
public mockProperty<T, U>(instance: T, propertyName: string, propertyValue: U): T {
|
|
Object.defineProperty(
|
|
instance,
|
|
propertyName,
|
|
{
|
|
get: (): U => { return propertyValue; },
|
|
set: (value: U): void => { propertyValue = value; },
|
|
});
|
|
|
|
return instance;
|
|
}
|
|
}
|