Constructor
new ObjectMock(instanceopt)
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
instance |
Object |
<optional> |
{}
|
The object instance on which the mocks will be created. If omitted, a default empty object will be used. |
Members
ctor :function
- Source:
Returns a reference to the constructor of the mocked object. This is
a mock constructor that returns a reference to the object being mocked.
Type:
- function
instance :Object
- Source:
A refence to the object that is being mocked.
Type:
- Object
mocks
- Source:
Reference to an object containing references to mocks for each method
on the instance that has been mocked.
Methods
addMock(methodName, returnValueopt) → {Object}
- Source:
Adds a mock for the specified method.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
methodName |
String | The name of the method to be mocked. If the method does not exist, an empty placeholder method will be creted and then mocked. | |
returnValue |
* |
<optional> |
The return value of the mocked method. If this parameter is a function, the function will be invoked, and its response will be returned. |
Returns:
A reference to the mock object (can be used to chain
method calls)
- Type
- Object
addPromiseMock(methodName) → {Object}
- Source:
Adds a mock for the specified method, treating the method as one that
returns a promise.
Parameters:
Name | Type | Description |
---|---|---|
methodName |
String | The name of the method to be mocked. If the method does not exist, an empty placeholder method will be creted and then mocked. |
Returns:
A reference to the mock object (can be used to chain
method calls)
- Type
- Object
restore(methodName) → {Object}
- Source:
Removes a mock for the specified method, and restores the original
method. If no mocks have been defined for the specified method name,
no changes will be made for that method.
Parameters:
Name | Type | Description |
---|---|---|
methodName |
String | The name of the method for which mocks will be removed. |
Returns:
A reference to the mock object (can be used to chain
method calls)
- Type
- Object