Mock

Mock

Class that creates a mock method on an object, and provides useful methods to track the response returned on each call.

This class is not meant to be instantiated directly, but is designed for use within the ObjectMock class.

Constructor

new Mock(instance, methodName, returnValue)

Source:
Parameters:
Name Type Description
instance Object The object instance on which the method will be mocked.
methodName String The name of the method on the object that needs to be mocked. If the specified method does not exist, a placeholder method will be injected into the instance which will then be mocked.
returnValue * | function A return value that will be returned by the mock method. If a function is passed in, the function will be invoked, and ther return value of the function will be returned as the response.

Members

instance :Object

Source:
Returns a reference to the instance object that has the mocks applied to it.
Type:
  • Object

methodName :String

Source:
Returns the name of the mock, which is the name of the method that has been mocked.
Type:
  • String

responses :Array

Source:
Returns a list of responses returned by the mock up to the current time. Responses may be promises depending on how the mock has been configured.
Type:
  • Array

ret :*|Error

Source:
Returns the response from the first mock invocation. If the mock has not been invoked yet, an Error object will be returned.
Type:
  • * | Error

stub :Object

Source:
Returns a reference to the stub method generated by this class. This property can be used to examine the call history and parameters of the mocked method.
Type:
  • Object

Methods

reset()

Source:
Clears all responses that have been tracked up to this point, and also resets the mock's call history.