# Namespace goog.testing

code »

## Interfaces

goog.testing.MockInterface
  No Description.

## Classes

goog.testing.AsyncTestCase
  A test case that is capable of running tests the contain asynchronous logic.
goog.testing.FunctionCall
  Struct for a single function call.
goog.testing.JsUnitException
  No Description.
goog.testing.LooseExpectationCollection
  This class is an ordered collection of expectations for one method.
goog.testing.LooseMock
  This is a mock that does not care about the order of method calls.
goog.testing.Mock
  The base class for a mock object.
goog.testing.MockClock
  Class for unit testing code that uses setTimeout and clearTimeout.
goog.testing.MockControl
  Controls a set of mocks.
goog.testing.MockExpectation
  This is a class that represents an expectation.
goog.testing.ObjectPropertyString
  Object to pass a property name as a string literal and its containing object when the JSCompiler is rewriting these names.
goog.testing.PropertyReplacer
  Helper class for stubbing out variables and object properties for unit tests.
goog.testing.StrictMock
  This is a mock that verifies that methods are called in the order that they are specified during the recording phase.
goog.testing.TestCase
  A class representing a JsUnit test case.
goog.testing.TestRunner
  Construct a test runner.

Show:Public Protected Private

## Global Functions

code »goog.testing.FunctionMock ( opt_functionName, opt_strictness ) ⇒ `goog.testing.MockInterface`

Class used to mock a function. Useful for mocking closures and anonymous callbacks etc. Creates a function object that extends goog.testing.Mock.

Parameters

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

The mocked function.

code »goog.testing.GlobalFunctionMock ( functionName, opt_strictness ) ⇒ `!goog.testing.MockInterface`

Mocks a global / top-level function. Creates a goog.testing.MethodMock in the global scope with the name specified by functionName.

Parameters

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

The mocked global function.

code »goog.testing.MethodMock ( scope, functionName, opt_strictness ) ⇒ `!goog.testing.MockInterface`

Mocks an existing function. Creates a goog.testing.FunctionMock and registers it in the given scope with the name specified by functionName.

Parameters

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

The mocked method.

code »goog.testing.createConstructorMock ( scope, constructorName, opt_strictness ) ⇒ `!goog.testing.MockInterface`

Convenience method for creating a mock for a constructor. Copies class members to the mock.

When mocking a constructor to return a mocked instance, remember to create the instance mock before mocking the constructor. If you mock the constructor first, then the mock framework will be unable to examine the prototype chain when creating the mock instance.

Parameters

scope: `Object`
  The scope of the constructor to be mocked out.
constructorName: `string`
  The name of the constructor we're going to mock.
opt_strictness: `number=`
  One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.

Returns

The mocked constructor.

code »goog.testing.createFunctionMock ( opt_functionName, opt_strictness ) ⇒ `goog.testing.MockInterface`

Convenience method for creating a mock for a function.

Parameters

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

The mocked function.

code »goog.testing.createGlobalFunctionMock ( functionName, opt_strictness ) ⇒ `goog.testing.MockInterface`

Convenience method for creating a mocks for a global / top-level function.

Parameters

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

The mocked global function.

code »goog.testing.createMethodMock ( scope, functionName, opt_strictness ) ⇒ `!goog.testing.MockInterface`

Convenience method for creating a mock for a method.

Parameters

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

The mocked global function.

code »goog.testing.recordConstructor ( ctor ) ⇒ `!Function`

Same as `goog.testing.recordFunction` but the recorded function will have the same prototype and static fields as the original one. It can be used with constructors.

Parameters

ctor: `!Function`
  The function to wrap and record.

Returns

The wrapped function.

code »goog.testing.recordFunction ( opt_f ) ⇒ `!Function`

Wraps the function into another one which calls the inner function and records its calls. The recorded function will have 3 static methods: `getCallCount`, `getCalls` and `getLastCall` but won't inherit the original function's prototype and static fields.

Parameters

opt_f: `!Function=`
  The function to wrap and record. Defaults to `goog.nullFunction`.

Returns

The wrapped function.