labs.mock

Classes

goog.labs.mock.MethodBinding_
Represents a binding between a method name, args and a stub.
goog.labs.mock.MockFunctionManager_
Sets up mock for the given function, stubbing out. By default, all stubs return undefined, though stubs can be later defined using goog.labs.mock.when.
goog.labs.mock.MockManager_
Base class that provides basic functionality for creating, adding and finding bindings, offering an executor method that is called when a call to the stub is made, an array to hold the bindings and the mocked item, among other things.
goog.labs.mock.MockObjectManager_
Sets up mock for the given object (or class), stubbing out all the defined methods. By default, all stubs return undefined, though stubs can be later defined using goog.labs.mock.when.
goog.labs.mock.MockSpyManager_
Sets up the spying behavior for the given object.
goog.labs.mock.StubBinder_
The stub binder is the object that helps define the stubs by binding method name to the stub method.
goog.labs.mock.VerificationError
Error thrown when verification failed.

Public Protected Private

Global Functions

goog.labs.mock.formatMethodCall_(methodNameopt_args) string
Returns a nicely formatted, readble representation of a method call.
Arguments:
methodName : string
The name of the method.
opt_args : Array=
The method arguments.
Returns: string  The string representation of the method call.
code »
goog.labs.mock.formatValue_(objopt_id) string
This is just another implementation of goog.debug.deepExpose with a more compact format.
Arguments:
obj : *
The object whose string representation will be returned.
opt_id : boolean=
Whether to include the id of objects or not. Defaults to true.
Returns: string  The string representation of the object.
code »
goog.labs.mock.getFunctionName_(func) string
Returns a name to identify a function. Named functions return their names, unnamed functions return a string of the form '#anonymous{ID}' where ID is a unique identifier for each anonymous function.
Arguments:
func : !Function
The function.
Returns: string  The function name.
code »
goog.labs.mock.getUid(obj) number
A unique Id generator that does not modify the object.
Arguments:
obj : Object!
The object whose unique ID we want to generate.
Returns: number  an unique id for the object.
code »
goog.labs.mock.mock(objectOrClass) !Object
Mocks a given object or class.
Arguments:
objectOrClass : !Object
An instance or a constructor of a class to be mocked.
Returns: !Object  The mocked object.
code »
goog.labs.mock.mockFunction(func) !Function
Mocks a given function.
Arguments:
func : !Function
A function to be mocked.
Returns: !Function  The mocked function.
code »
goog.labs.mock.spy(obj) !Object
Spies on a given object.
Arguments:
obj : !Object
The object to be spied on.
Returns: !Object  The spy object.
code »
goog.labs.mock.verify(obj) !Object
Returns an object that can be used to verify calls to specific methods of a given mock.
Arguments:
obj : !Object
The mocked object.
Returns: !Object  The verifier.
code »
goog.labs.mock.when(mockObject) !goog.labs.mock.StubBinder_
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);
Arguments:
mockObject : !Object
The mocked object.
Returns: !goog.labs.mock.StubBinder_  The property binder.
code »

Global Properties

goog.labs.mock.PROTOTYPE_FIELDS_ :
This array contains the name of the functions that are part of the base Object prototype. Basically a copy of goog.object.PROTOTYPE_FIELDS_.
Code »
goog.labs.mock.uid_ :
An array to store objects for unique id generation.
Code »

Package labs

Package Reference