Constructor
new Mock(instance, methodName, returnValue)
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
Returns a reference to the instance object that has the mocks applied to
it.
Type:
- Object
methodName :String
Returns the name of the mock, which is the name of the method that has
been mocked.
Type:
- String
responses :Array
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
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
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()
Clears all responses that have been tracked up to this point, and also
resets the mock's call history.