Veve

Classes

TrackFn Interface

veve / TrackFn

Class: TrackFn

Defined in: framework/Fn.ts:45

Implements

Constructors

new TrackFn()

new TrackFn(_implementation): TrackFn

Defined in: framework/Fn.ts:203

Parameters

_implementation

Function

Returns

TrackFn

Methods

clear()

clear(): TrackFn

Defined in: framework/Fn.ts:182

Clears all recorded calls and arguments but retains custom behavior configurations

Returns

TrackFn

The cleared tracked function with retained behavior configurations

Example

const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.clear()

getAllArgs()

Call Signature

getAllArgs(): readonly any[][]

Defined in: framework/Fn.ts:55

Retrieves the arguments passed to all function calls

Returns

readonly any[][]

An array of argument arrays for each call

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.getAllArgs()

Call Signature

getAllArgs(): readonly any[][]

Defined in: framework/Fn.ts:306

Retrieves the arguments passed to all function calls

Returns

readonly any[][]

An array of argument arrays for each call

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.getAllArgs()

getArgsForCall()

Call Signature

getArgsForCall(index): undefined | any[]

Defined in: framework/Fn.ts:67

Retrieves the arguments passed to a specific function call by index

Parameters
index

number

The index of the function call

Returns

undefined | any[]

The arguments of the specified call, or undefined if not found

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.getArgsForCall(1)

Call Signature

getArgsForCall(index): undefined | any[]

Defined in: framework/Fn.ts:310

Retrieves the arguments passed to a specific function call by index

Parameters
index

number

The index of the function call

Returns

undefined | any[]

The arguments of the specified call, or undefined if not found

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.getArgsForCall(1)

getCall()

getCall(index): undefined | FunctionCall

Defined in: framework/Fn.ts:294

Parameters

index

number

Returns

undefined | FunctionCall


getCallCount()

getCallCount(): number

Defined in: framework/Fn.ts:302

Returns

number


getCalls()

getCalls(): readonly FunctionCall[]

Defined in: framework/Fn.ts:290

Returns

readonly FunctionCall[]


getExceptions()

Call Signature

getExceptions(): readonly FunctionException[]

Defined in: framework/Fn.ts:89

Retrieves the exceptions thrown during function calls

Returns

readonly FunctionException[]

An array of thrown exceptions

Example
const throwError = () => { throw new Error('Test error') }
const trackFn = Fn(throwError)
trackFn.getExceptions()

Call Signature

getExceptions(): readonly FunctionException[]

Defined in: framework/Fn.ts:318

Retrieves the exceptions thrown during function calls

Returns

readonly FunctionException[]

An array of thrown exceptions

Example
const throwError = () => { throw new Error('Test error') }
const trackFn = Fn(throwError)
trackFn.getExceptions()

getLatestCall()

getLatestCall(): undefined | FunctionCall

Defined in: framework/Fn.ts:298

Returns

undefined | FunctionCall


getReturnValues()

Call Signature

getReturnValues(): readonly any[]

Defined in: framework/Fn.ts:78

Retrieves the return values of all function calls

Returns

readonly any[]

An array of return values for each call

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.getReturnValues()

Call Signature

getReturnValues(): readonly any[]

Defined in: framework/Fn.ts:314

Retrieves the return values of all function calls

Returns

readonly any[]

An array of return values for each call

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.getReturnValues()

reset()

Call Signature

reset(): TrackFn

Defined in: framework/Fn.ts:171

Resets the state of the tracked function, clearing all recorded calls, arguments, and results

Returns

TrackFn

The reset tracked function

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.reset()

Call Signature

reset(): TrackFn

Defined in: framework/Fn.ts:261

Resets the state of the tracked function, clearing all recorded calls, arguments, and results

Returns

TrackFn

The reset tracked function

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.reset()

return()

return(value): TrackFn

Defined in: framework/Fn.ts:136

Sets the return value for the tracked function

Parameters

value

any

The value to be returned

Returns

TrackFn

The updated tracked function with the configured return value

Example

const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.return(5)

returns()

returns(value): TrackFn

Defined in: framework/Fn.ts:272

Parameters

value

any

Returns

TrackFn


throw()

throw(error): TrackFn

Defined in: framework/Fn.ts:148

Configures the tracked function to throw a specific error

Parameters

error

Error

The error to be thrown

Returns

TrackFn

The updated tracked function with the configured error

Example

const throwError = () => { throw new Error('Test error') }
const trackFn = Fn(throwError)
trackFn.throw(new Error('Custom error'))

throws()

throws(error): TrackFn

Defined in: framework/Fn.ts:277

Parameters

error

Error

Returns

TrackFn


track()

track(): Function

Defined in: framework/Fn.ts:206

Returns

Function


use()

Call Signature

use(fn): TrackFn

Defined in: framework/Fn.ts:160

Replaces the tracked function with a custom implementation

Parameters
fn

(...args) => any

The custom function to be used

Returns

TrackFn

The updated tracked function with the custom implementation

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.use((a, b) => a * b)

Call Signature

use(fn): TrackFn

Defined in: framework/Fn.ts:284

Replaces the tracked function with a custom implementation

Parameters
fn

Function

The custom function to be used

Returns

TrackFn

The updated tracked function with the custom implementation

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.use((a, b) => a * b)

wasCalled()

Call Signature

wasCalled(): boolean

Defined in: framework/Fn.ts:100

Checks if the tracked function was called at least once

Returns

boolean

true if the function was called, otherwise false

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.wasCalled()

Call Signature

wasCalled(): boolean

Defined in: framework/Fn.ts:322

Checks if the tracked function was called at least once

Returns

boolean

true if the function was called, otherwise false

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.wasCalled()

wasCalledTimes()

Call Signature

wasCalledTimes(n): boolean

Defined in: framework/Fn.ts:124

Checks if the tracked function was called a specific number of times

Parameters
n

number

The number of calls to check

Returns

boolean

true if the function was called exactly n times, otherwise false

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.wasCalledTimes(2)

Call Signature

wasCalledTimes(n): boolean

Defined in: framework/Fn.ts:334

Checks if the tracked function was called a specific number of times

Parameters
n

number

The number of calls to check

Returns

boolean

true if the function was called exactly n times, otherwise false

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.wasCalledTimes(2)

wasCalledWith()

Call Signature

wasCalledWith(...args): boolean

Defined in: framework/Fn.ts:112

Checks if the tracked function was called with specific arguments

Parameters
args

...any[]

The arguments to check

Returns

boolean

true if the function was called with the specified arguments, otherwise false

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.wasCalledWith(1, 2)

Call Signature

wasCalledWith(...args): boolean

Defined in: framework/Fn.ts:326

Checks if the tracked function was called with specific arguments

Parameters
args

...any[]

The arguments to check

Returns

boolean

true if the function was called with the specified arguments, otherwise false

Example
const add = (a, b) => a + b
const trackFn = Fn(add)
trackFn.wasCalledWith(1, 2)