MCPcopy Create free account
hub / github.com/denoland/std / spy

Function spy

testing/mock.ts:943–967  ·  view source on GitHub ↗
(
  funcOrConstOrSelf?:
    | ((this: Self, ...args: Args) => Return)
    | (new (...args: Args) => Self)
    | Self,
  property?: keyof Self,
)

Source from the content-addressed store, hash-verified

941 GetReturnFromProp<Self, Prop>
942>;
943export function spy<
944 Self,
945 Args extends unknown[],
946 Return,
947>(
948 funcOrConstOrSelf?:
949 | ((this: Self, ...args: Args) => Return)
950 | (new (...args: Args) => Self)
951 | Self,
952 property?: keyof Self,
953): SpyLike<Self, Args, Return> {
954 if (!funcOrConstOrSelf) {
955 return functionSpy<Self, Args, Return>();
956 } else if (property !== undefined) {
957 return methodSpy<Self, Args, Return>(funcOrConstOrSelf as Self, property);
958 } else if (funcOrConstOrSelf.toString().startsWith("class")) {
959 return constructorSpy<Self, Args>(
960 funcOrConstOrSelf as new (...args: Args) => Self,
961 );
962 } else {
963 return functionSpy<Self, Args, Return>(
964 funcOrConstOrSelf as (this: Self, ...args: Args) => Return,
965 );
966 }
967}
968
969/** An instance method replacement that records all calls made to it. */
970export interface Stub<

Callers 15

spyLoopIterationsFunction · 0.90
parse_test.tsFile · 0.90
parse_test.tsFile · 0.90
time_test.tsFile · 0.90
stubFunction · 0.90
hookFnsFunction · 0.90
bdd_test.tsFile · 0.90
assertOptionsFunction · 0.90
assertIgnoreOptionsFunction · 0.90
assertOnlyFunction · 0.90
assertHooksFunction · 0.90
constructorMethod · 0.90

Calls 5

functionSpyFunction · 0.85
methodSpyFunction · 0.85
constructorSpyFunction · 0.85
startsWithMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected