The goog.testing.MockControl Class

goog.testing.MockControl()

Controls a set of mocks. Controlled mocks are replayed, verified, and cleaned-up at the same time.

.$replayAll()

Calls replay on each controlled mock.

.$resetAll()

Calls reset on each controlled mock.

.$tearDown()

Calls tearDown on each controlled mock, if necesssary.

.$verifyAll()

Calls verify on each controlled mock.

.addMock(mock)

Takes control of this mock.

mock {goog.testing.MockInterface}
Mock to be controlled.
returns {goog.testing.MockInterface}
The same mock passed in, for convenience.

.createConstructorMock(scope, constructorName, opt_strictness)

Creates a controlled MethodMock for a constructor. Passes its arguments through to the MethodMock constructor. See {@link goog.testing.createConstructorMock} for details.

scope {Object}
The scope of the constructor to be mocked out.
constructorName {string}
The name of the function we're going to mock.
opt_strictness {number=}
One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.
returns {goog.testing.MockInterface}
The mocked method.

.createFunctionMock(opt_functionName, opt_strictness)

Creates a controlled FunctionMock. Passes its arguments through to the FunctionMock constructor.

opt_functionName {string=}
The optional name of the function to mock set to '[anonymous mocked function]' if not passed in.
opt_strictness {number=}
One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.
returns {goog.testing.MockInterface}
The mocked function.

.createGlobalFunctionMock(functionName, opt_strictness)

Creates a controlled GlobalFunctionMock. Passes its arguments through to the GlobalFunctionMock constructor.

functionName {string}
The name of the function we're going to mock.
opt_strictness {number=}
One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.
returns {goog.testing.MockInterface}
The mocked function.

.createLooseMock(objectToMock, opt_ignoreUnexpectedCalls, opt_mockStaticMethods, opt_createProxy)

Creates a controlled LooseMock. Passes its arguments through to the LooseMock constructor.

objectToMock {Object}
The object to mock.
opt_ignoreUnexpectedCalls {boolean=}
Whether to ignore unexpected calls.
opt_mockStaticMethods {boolean=}
An optional argument denoting that a mock should be constructed from the static functions of a class.
opt_createProxy {boolean=}
An optional argument denoting that a proxy for the target mock should be created.
returns {goog.testing.LooseMock}
The mock object.

.createMethodMock(scope, functionName, opt_strictness)

Creates a controlled MethodMock. Passes its arguments through to the MethodMock constructor.

scope {Object}
The scope of the method to be mocked out.
functionName {string}
The name of the function we're going to mock.
opt_strictness {number=}
One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.
returns {goog.testing.MockInterface}
The mocked method.

.createStrictMock(objectToMock, opt_mockStaticMethods, opt_createProxy)

Creates a controlled StrictMock. Passes its arguments through to the StrictMock constructor.

objectToMock {Object}
The object to mock.
opt_mockStaticMethods {boolean=}
An optional argument denoting that a mock should be constructed from the static functions of a class.
opt_createProxy {boolean=}
An optional argument denoting that a proxy for the target mock should be created.
returns {goog.testing.StrictMock}
The mock object.