Operation

Operation

This class represents a single function call, property get, or property set. It can represent any of those things in the current tense ("this is the operation that is currently running") or in the past tense ("the historyList is full of operations that have already run"). Triggers use Operations in the present tense, and have the opportunity to modify the Operation as it is happening. Filters operate on the historyList of the Wrapper, which is the history of all the times a function has been called or a property has been set / get.

Operations may either represent an action taken on function or a property, as represented by the Operator.type property. If a Operator.type is "property", the Operator.getOrSet property will further distinguish whether this operation was a get operation (that is, getting the value from the property) or set operation (that is, assigning a value to the property).

Operations extend the Expect class, which enables expect methods to be run against the Operator. Again these expectations can be run in real-time during a Trigger, or after-the-fact from the historyList.

Constructor

new Operation(wrapper, desc)

Source:

Creates a new Operation

Parameters:
Name Type Description
wrapper Wrapper

The Wrapper that created this Operation

desc Object

The default values of the Operation

Members

argList :any

Source:

The arguments that were or will be passed to the function call. Only applies to functions.

Type:
  • any

context :any

Source:

The this value that was or will be used for the function call. Only applies to functions.

Type:
  • any

exception :Error|null

Source:

The Error that was or will be thrown. If null, there was no Error.

Type:
  • Error | null

getOrSet :String

Source:

Whether this was a property "set" (assignment) or a property "get" (retreiving the value). Only applies to properties.

Type:
  • String

postCall :Boolean

Source:

Set by a Trigger to be true if the operation record is in it's "post-call" phase.

Type:
  • Boolean

preCall :Boolean

Source:

Set by a Trigger to be true if the operation record is currently in it's "pre-call" phase -- that is before the call to the wrapped thing has actually happened.

Type:
  • Boolean

retVal :any

Source:

The value that was or will be returned.

Type:
  • any

setVal :any

Source:

The value that was or will be used for a property "set". Only applies to properties.

Type:
  • any

type :String

Source:

The type of operation record this is, either "function" or "property"

Type:
  • String

wrapper :Wrapper

Source:

The Wrapper that created this call

Type:

Methods

(static) expectCallArgs(…args) → {Trigger|Boolean}

Source:

Evaluates whether the arguments to a function match the ...args.

Parameters:
Name Type Attributes Description
args any <repeatable>

The list of arguments to validate for the function call.

Throws:
  • If called with more or less than one argument

    Type
    TypeError
  • If called by a Trigger that doesn't match the expected return value

    Type
    ExpectError
Returns:

When called on a Trigger, the expectation is stored for future evaluation and the Trigger value is returned to make this chainable. When called on a Operation, the expectation is evaluated immediately and true is returned if the expectation passed; false if it failed.

Type
Trigger | Boolean

(static) expectCallContext(context) → {Trigger|Boolean}

Source:

Evaluates whether the context (this) of a function call matches the context parameter.

Parameters:
Name Type Description
context Object

The expected this for the function. Is compared by a strict deep-equals.

Throws:
  • If called on a wrapped function, or with more or less than one argument

    Type
    TypeError
  • If called by a Trigger that doesn't match the expected call context (this value)

    Type
    ExpectError
Returns:

When called on a Trigger, the expectation is stored for future evaluation and the Trigger value is returned to make this chainable. When called on a Operation, the expectation is evaluated immediately and true is returned if the expectation passed; false if it failed.

Type
Trigger | Boolean

(static) expectCustom(cb) → {Trigger|Boolean}

Source:

Evaluates the callback function

Parameters:
Name Type Description
cb Operation~customExpectCallback

Callback function that will determine whether the expecation passes or fails. See customExpectCallback for more details.

Throws:
  • If called with more or less than one argument, or the first argument isn't a Function

    Type
    TypeError
  • If called by a Trigger and the custom function returns an Error or a String

    Type
    ExpectError
Returns:

When called on a Trigger, the expectation is stored for future evaluation and the Trigger value is returned to make this chainable. When called on a Operation, the expectation is evaluated immediately and true is returned if the expectation passed; false if it failed.

Type
Trigger | Boolean

(static) expectException(exception) → {Trigger|Boolean}

Source:

Expects that the function call or property set / get threw an Error that strictly matches the exception arguemnt.

Parameters:
Name Type Description
exception Error | null

The Error (or class that inherits from Error) that is expected to strictly match. A strict comparison between errors evaluates that the Error.name and Error.message are the exact same. If exception is null, it will expecct that there was no Error thrown.

Throws:
  • If called with more or less than one argument, or with an argument that isn't an Error or null

    Type
    TypeError
  • If called by a Trigger that doesn't throw the expected exception (Error) or throwns an unexpected exception (if the expected exception was null)

    Type
    ExpectError
Returns:

When called on a Trigger, the expectation is stored for future evaluation and the Trigger value is returned to make this chainable. When called on a Operation, the expectation is evaluated immediately and true is returned if the expectation passed; false if it failed.

Type
Trigger | Boolean

(static) expectReturn(retVal) → {Trigger|Boolean}

Source:

Evaluates whether the call or get returned the value retVal.

Parameters:
Name Type Description
retVal any

The value that is expected to be returned from the function call or property getter.

Throws:
  • If called with more or less than one argument

    Type
    TypeError
  • If called by a Trigger that doesn't match the expected return value

    Type
    ExpectError
Returns:

When called on a Trigger, the expectation is stored for future evaluation and the Trigger value is returned to make this chainable. When called on a Operation, the expectation is evaluated immediately and true is returned if the expectation passed; false if it failed.

Type
Trigger | Boolean

(static) expectSetVal(setVal) → {Trigger|Boolean}

Source:

Evaluates the value that is set on a property during assignment (e.g. - obj.prop = setVal) and expects the value to strictly equal the setVal argument.

Parameters:
Name Type Description
setVal any

The value that is expected to be set on the property. An undefined value is allowed, but the value undefined must be passed explicitly to expectSetVal.

Throws:
  • If called with more or less than one argument

    Type
    TypeError
  • If called by a Trigger that doesn't receive the expected set argument

    Type
    ExpectError
Returns:

When called on a Trigger, the expectation is stored for future evaluation and the Trigger value is returned to make this chainable. When called on a Operation, the expectation is evaluated immediately and true is returned if the expectation passed; false if it failed.

Type
Trigger | Boolean

Type Definitions

customExpectCallback(curr) → {null|ExpectError}

Source:

This is a description of the callback used by expectCustom.

Parameters:
Name Type Description
curr Operation

The current function call or property / set get.

Returns:

null if expectation was successful. Returns ExpectError containing the message for the failed expectation otherwise.

Type
null | ExpectError