static Spies

Root object for the library.

Methods

anyCallCountOf(Function target) => Number

Returns the number of call counts for the target of any arguments.

target

Function

The function whose call count should be returned.

Function target

The function whose call count should be returned.

return Number

Number of invocations on the given function.

callCountOf(SpiedFn target) => Function

Returns a function that returns the call count of the given target when called with the given arguments. For example: Spies.callCountOf(fn)(1, 2) returns the number of calls that function fn was called with arguments (1, 2).

If the passed in function is not a spy, this will return 0.

target

SpiedFn

The function whose call count should be returned.

SpiedFn target

The function whose call count should be returned.

return Function

Function that returns the call counts of the given function.

invocationsOf(SpiedFn target) => Function

Returns a function that returns the invocations of the given target when called with the given arguments. For example: Spies.invocationsOf(fn)(1, 2) returns an array of invocations matching when fn is called with arguments (1, 2).

An invocation object consists of two values:

  • timestamp: This is the timestamp of the call. This only determines ordering, not actual time.
  • args: This is an array of arguments that the function received at that time.

target

SpiedFn

The function whose invocations should be returned.

SpiedFn target

The function whose invocations should be returned.

return Function

Function thar returns the invocations of the given function.

reset(Function | Object target)

Restores the given function or recursively all functions in the given object to its original implementation and removes all records related to it. Or, restores all known functions, if no arguments is given.

[target]

Function | Object

The function or object to be reset.

Function | Object [target]

The function or object to be reset.

spiedFunction() => SpiedFn

Creates a spied function.

return SpiedFn

Spied function.

spy(Object scope, String name) => Object | Function

Spies the given function, or recursively all functions in the given object.

scope

Object

The Object to be spied on, or the object containing the function to be spied on.

[name]

String

The name of the function to be spied on. If not specified, this will spy all functions in the scope recursively.

Object scope

The Object to be spied on, or the object containing the function to be spied on.

String [name]

The name of the function to be spied on. If not specified, this will spy all functions in the scope recursively.

return Object | Function

The spied function, or the spied object.

stub(Function | Object ctor) => Object

Creates a stub for the given constructor or object. All functions will be replaced by a noop function.

ctor

Function | Object

The constructor to be stubbed, or object.

Function | Object ctor

The constructor to be stubbed, or object.

return Object

The stub object.