goog.testing.Mock
Classgoog.testing.Mock(objectToMock, opt_mockStaticMethods, opt_createProxy)
The base class for a mock object.
objectToMock
{Object
|Function
}
opt_mockStaticMethods
{boolean
=}
opt_createProxy
{boolean
=}
.$anyTimes()
Allows the expectation to be called any number of times.
goog.testing.Mock
}
.$argumentListVerifiers_
{Object
}Map of argument name to optional argument list verifier function.
.$argumentsAsString(args)
Render the provided argument array to a string to help clients with debugging tests.
args
{Array
.<*>?}
string
}
.$atLeastOnce()
Allows the expectation to be called any number of times, as long as it's called once.
goog.testing.Mock
}
.$atMostOnce()
Allows the expectation to be called 0 or 1 times.
goog.testing.Mock
}
.$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.
expectation
{goog.testing.MockExpectation
}
args
{Array
}
.$does(func)
Specifies a function to call for currently pending expectation. Note, that using this method overrides declarations made using $returns() and $throws() methods.
func
{Function
}
goog.testing.Mock
}
.$maybeThrow(expectation)
If the expectation expects to throw, this method will throw.
expectation
{goog.testing.MockExpectation
}
.$mockMethod(name)
The function that replaces all methods on the mock object.
name
{string
}
.$pendingExpectation
[protected] {goog.testing.MockExpectation
}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.
.$proxy
{Object
}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.
.$recordAndThrow(ex)
[protected]Throws an exception and records that an exception was thrown.
ex
{Object
}
.$recordCall(name, args)
[protected]Records an actual method call, intended to be overridden by a subclass. The subclass must find the pending expectation and return the correct value.
name
{string
}
args
{Array
}
.$recordExpectation()
[protected]Records the currently pending expectation, intended to be overridden by a subclass.
.$registerArgumentListVerifier(methodName, fn)
Registers a verfifier function to use when verifying method argument lists.
methodName
{string
}
fn
{Function
}
goog.testing.Mock
}
.$replay()
Switches from recording to replay mode.
.$reset()
Resets the state of this mock object. This clears all pending expectations without verifying, and puts the mock in recording mode.
.$returns(val)
Specifies a return value for the currently pending expectation.
val
{*}
goog.testing.Mock
}
.$throwCallException(name, args, opt_expectation)
Throw an exception based on an incorrect method call.
name
{string
}
args
{Array
.<*>?}
opt_expectation
{goog.testing.MockExpectation
=}
.$throwException(comment, opt_message)
[protected]Throws an exception and records that an exception was thrown.
comment
{string
}
opt_message
{?string
=}
.$throws(val)
Specifies a value for the currently pending expectation to throw.
val
{*}
goog.testing.Mock
}
.$times(times)
Specifies the number of times the expectation should be called.
times
{number
}
goog.testing.Mock
}
.$verify()
Verify that all of the expectations were met. Should be overridden by subclasses.
.$verifyCall(expectation, name, args)
Verifies that a method call matches an expectation.
expectation
{goog.testing.MockExpectation
}
name
{string
}
args
{Array
.<*>?}
boolean
}
.LOOSE
{number
}Option that may be passed when constructing function, method, and constructor mocks. Indicates that the expected calls should be accepted in any order.
.STRICT
{number
}Option that may be passed when constructing function, method, and constructor mocks. Indicates that the expected calls should be accepted in the recorded order only.