goog.labs.mock
Functions
getUid( obj ) → number
number
mock( objectOrClass ) → Object
Object
mockConstructor<T>( ctor ) → function(new: T, ...?)
function(new: T, ...?)
Mocks a given constructor.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
mockFunction( opt_func ) → Function
Function
Mocks a given function.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
spy( obj ) → Object
Object
verify( obj, opt_verificationMode ) → ?
?
Returns an object that can be used to verify calls to specific methods of a given mock.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
waitAndVerify( obj, ...verificationOrTimeoutModes ) → ?
?
Returns an object that can be used to wait for calls to specific methods of a given mock.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
when( mockObject ) → ?
?
Facilitates (and is the first step in) setting up stubs. Obtains an object on which, the method to be mocked is called to create a stub. Sample usage:
var mockObj = goog.labs.mock.mock(objectBeingMocked); goog.labs.mock.when(mockObj).getFoo(3).thenReturn(4);
Subsequent calls to when
take precedence over earlier calls, allowing
users to set up default stubs in setUp methods and then override them in
individual tests.
If a user wants sequential calls to their stub to return different
values, they can chain calls to then
or thenReturn
as
follows:
var mockObj = goog.labs.mock.mock(objectBeingMocked); goog.labs.mock.when(mockObj).getFoo(3) .thenReturn(4) .then(function() { throw new Error('exceptional case'); });
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
Properties
DescriptorStubBinder → {asDataProperty: function(?=): undefined, get: (Function|undefined), set: (Function|undefined)}
{asDataProperty: function(?=): undefined, get: (Function|undefined), set: (Function|undefined)}
A type for a mocked accessor descriptor.