alsatian-test/alsatian

View on GitHub
packages/alsatian/core/spying/spy-on.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { RestorableFunctionSpy } from "../spying";

export function SpyOn<ObjectType>(
    target: ObjectType,
    functionName: keyof ObjectType
): RestorableFunctionSpy {
    if (target[functionName] instanceof Function) {
        return new RestorableFunctionSpy(target, functionName as string);
    } else {
        throw new TypeError(`${functionName} is not a function.`);
    }
}