Class goog.testing.StrictMock

code »
goog.testing.Mock
  └ goog.testing.StrictMock
All implemented interfaces:
goog.testing.MockInterface

This is a mock that verifies that methods are called in the order that they are specified during the recording phase. Since it verifies order, it follows 'fail fast' semantics. If it detects a deviation from the expectations, it will throw an exception and not wait for verify to be called.

Constructor

goog.testing.StrictMock ( objectToMock, opt_mockStaticMethods, opt_createProxy )
Parameters
objectToMock: (Object|Function)
The object that should be mocked, or the constructor of an 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.
Show:

Instance Methods

Defined in goog.testing.StrictMock

code »$recordCall ( name, args )*
Parameters
name
args

Defined in goog.testing.Mock

Allows the expectation to be called any number of times.

Returns
This mock object.

Render the provided argument array to a string to help clients with debugging tests.

Parameters
args: ?Array
The arguments passed to the mock.
Returns
Human-readable string.

Allows the expectation to be called any number of times, as long as it's called once.

Returns
This mock object.

Allows the expectation to be called 0 or 1 times.

Returns
This mock object.
code »$do ( expectation, args )*

If this expectation defines a function to be called, it will be called and its result will be returned. Otherwise, if the expectation expects to throw, it will throw. Otherwise, this method will return defined value.

Parameters
expectation: goog.testing.MockExpectation
The expectation.
args: Array
The arguments to the method.
Returns
The return value expected by the mock.

Specifies a function to call for currently pending expectation. Note, that using this method overrides declarations made using $returns() and $throws() methods.

Parameters
func: Function
The function to call.
Returns
This mock object.

Initializes the functions on the mock object.

Parameters
objectToMock: Object
The object being mocked.
code »$maybeThrow ( expectation )

If the expectation expects to throw, this method will throw.

Parameters
expectation: goog.testing.MockExpectation
The expectation.
code »$mockMethod ( name )*

The function that replaces all methods on the mock object.

Parameters
name: string
The name of the method being mocked.
Returns
In record mode, returns the mock object. In replay mode, returns whatever the creator of the mock set as the return value.

Disallows the expectation from being called.

Returns
This mock object.

Allows the expectation to be called exactly once.

Returns
This mock object.

Throws an exception and records that an exception was thrown.

Parameters
ex: Object
Exception.
Throws
Object
#ex.

Registers a verfifier function to use when verifying method argument lists.

Parameters
methodName: string
The name of the method for which the verifierFn should be used.
fn: Function
Argument list verifier function. Should take 2 argument arrays as arguments, and return true if they are considered equivalent.
Returns
This mock object.

Switches from recording to replay mode.

Specifies a return value for the currently pending expectation.

Parameters
val: *
The return value.
Returns
This mock object.
code »$throwCallException ( name, args, opt_expectation )

Throw an exception based on an incorrect method call.

Parameters
name: string
Name of method called.
args: ?Array
Arguments passed to the mock.
opt_expectation: goog.testing.MockExpectation=
Expected next call, if any.
code »$throwException ( comment, opt_message )

Throws an exception and records that an exception was thrown.

Parameters
comment: string
A short comment about the exception.
opt_message: ?string=
A longer message about the exception.
Throws
Object
JsUnitException object.

Specifies a value for the currently pending expectation to throw.

Parameters
val: *
The value to throw.
Returns
This mock object.

Specifies the number of times the expectation should be called.

Parameters
times: number
The number of times this method will be called.
Returns
This mock object.
code »$verifyCall ( expectation, name, args )boolean

Verifies that a method call matches an expectation.

Parameters
expectation: goog.testing.MockExpectation
The expectation to check.
name: string
The name of the called method.
args: ?Array
The arguments passed to the mock.
Returns
Whether the call matches the expectation.

Instance Properties

Defined in goog.testing.StrictMock

Defined in goog.testing.Mock

Map of argument name to optional argument list verifier function.

The expectation currently being created. All methods that modify the current expectation return the Mock object for easy chaining, so this is where we keep track of the expectation that's currently being modified.

A proxy for the mock. This can be used for dependency injection in lieu of the mock if the test requires a strict instanceof check.

Whether or not we are in recording mode.

First exception thrown by this mock; used in $verify.

Static Properties