testing.MockClassFactory Extends
A factory used to create new mock class instances. It is able to generate both static and loose mocks. The MockClassFactory is a singleton since it tracks the classes that have been mocked internally.

Inheritance

Constructor

goog.testing.MockClassFactory()

Instance Methods

Public Protected Private
classHasMock_(className) boolean
Returns whether or not a given class has been mocked.
Arguments:
className : string
The name of the class.
Returns: boolean  Whether or not the given class name has a MockClassRecord.
code »
createProxy_(namespaceclassToMockclassName) !Function
Create a proxy class. A proxy will pass functions to the mock for a class. The proxy class only covers prototype methods. A static mock is not build simultaneously since it might be strict or loose. The proxy class inherits from the target class in order to preserve instanceof checks.
Arguments:
namespace : Object
A javascript namespace (e.g. goog.testing).
classToMock : Function
The class that will be proxied.
className : string
The name of the class.
Returns: !Function  The proxy for provided class.
code »
createStaticMock_(classToMockclassNameproxyisStrict) !goog.testing.StrictMock | !goog.testing.LooseMock
Creates either a loose or strict mock for the static functions of a given class.
Arguments:
classToMock : Function
The class whose static functions will be mocked. This should be the original class and not the proxy.
className : string
The name of the class.
proxy : Function
The proxy that will replace the original class.
isStrict : boolean
Whether or not the mock should be strict.
Returns: !goog.testing.StrictMock | !goog.testing.LooseMock  The mock created for the static functions of the provided class.
code »
findMockInstance_(classNameargs) goog.testing.StrictMock | goog.testing.LooseMock
Find a mock instance for a given class name and argument list.
Arguments:
className : string
The name of the class.
args : Array
The argument list to match.
Returns: goog.testing.StrictMock | goog.testing.LooseMock  The mock found for the given argument list.
code »
getClassName_(namespaceclassToMock) string
Iterates through a namespace to find the name of a given class. This is done solely to support compilation since string identifiers would break down. Tests usually aren't compiled, but the functionality is supported.
Arguments:
namespace : Object
A javascript namespace (e.g. goog.testing).
classToMock : Function
The class whose name should be returned.
Returns: string  The name of the class.
code »
getLooseMockClass(namespaceclassToMockvar_args) goog.testing.LooseMock
Gets a loose mock for a given class.
Arguments:
namespace : Object
A javascript namespace (e.g. goog.testing).
classToMock : Function
The class that will be mocked.
var_args : ...*
The arguments associated with this instance's constructor.
Returns: goog.testing.LooseMock  The mock created for the provided class.
code »
getLooseStaticMock(namespaceclassToMock) goog.testing.LooseMock
Gets a loose mock for the static functions of a given class.
Arguments:
namespace : Object
A javascript namespace (e.g. goog.testing).
classToMock : Function
The class whose static functions will be mocked. This should be the original class and not the proxy.
Returns: goog.testing.LooseMock  The mock created for the static functions of the provided class.
code »
getMockClass_(namespaceclassToMockisStrictctorArgs) !goog.testing.StrictMock | !goog.testing.LooseMock
Gets either a loose or strict mock for a given class based on a set of arguments.
Arguments:
namespace : Object
A javascript namespace (e.g. goog.testing).
classToMock : Function
The class that will be mocked.
isStrict : boolean
Whether or not the mock should be strict.
ctorArgs : goog.array.ArrayLike
The arguments associated with this instance's constructor.
Returns: !goog.testing.StrictMock | !goog.testing.LooseMock  The mock created for the provided class.
code »
getProxyCtor_(classNamemockFinder) !Function
Returns a proxy constructor closure. Since this is a constructor, "this" refers to the local scope of the constructed object thus bind cannot be used.
Arguments:
className : string
The name of the class.
mockFinder : Function
A bound function that returns the mock associated with a class given the constructor's argument list.
Returns: !Function  A proxy constructor.
code »
getProxyFunction_(fnName) !Function
Returns a proxy function for a mock class instance. This function cannot be used with bind since "this" must refer to the scope of the proxy constructor.
Arguments:
fnName : string
The name of the function that should be proxied.
Returns: !Function  A proxy function.
code »
getStaticMock_(namespaceclassToMockisStrict) goog.testing.StrictMock | goog.testing.LooseMock
Gets either a loose or strict mock for the static functions of a given class.
Arguments:
namespace : Object
A javascript namespace (e.g. goog.testing).
classToMock : Function
The class whose static functions will be mocked. This should be the original class and not the proxy.
isStrict : boolean
Whether or not the mock should be strict.
Returns: goog.testing.StrictMock | goog.testing.LooseMock  The mock created for the static functions of the provided class.
code »
getStrictMockClass(namespaceclassToMockvar_args) goog.testing.StrictMock
Gets a strict mock for a given class.
Arguments:
namespace : Object
A javascript namespace (e.g. goog.testing).
classToMock : Function
The class that will be mocked.
var_args : ...*
The arguments associated with this instance's constructor.
Returns: goog.testing.StrictMock  The mock created for the provided class.
code »
getStrictStaticMock(namespaceclassToMock) goog.testing.StrictMock
Gets a strict mock for the static functions of a given class.
Arguments:
namespace : Object
A javascript namespace (e.g. goog.testing).
classToMock : Function
The class whose static functions will be mocked. This should be the original class and not the proxy.
Returns: goog.testing.StrictMock  The mock created for the static functions of the provided class.
code »
reset()
Resests the factory by reverting all mocked classes to their original implementations and removing all MockClassRecords.
code »

Instance Properties

mockClassRecords_ :
A map from class name -> goog.testing.MockClassRecord.
Code »

Static Properties

goog.testing.MockClassFactory.PROTOTYPE_FIELDS_ :
The names of the fields that are defined on Object.prototype.
Code »
goog.testing.MockClassFactory.instance_ : goog.testing.MockClassFactory
A singleton instance of the MockClassFactory.
Code »

Package testing

Package Reference