goog.testing.MockClock
Classgoog.testing.MockClock
> goog.Disposable
goog.testing.MockClock(opt_autoInstall)
Class for unit testing code that uses setTimeout and clearTimeout. NOTE: If you are using MockClock to test code that makes use of goog.fx.Animation, then you must either: 1. Install and dispose of the MockClock in setUpPage() and tearDownPage() respectively (rather than setUp()/tearDown()). or 2. Ensure that every test clears the animation queue by calling mockClock.tick(x) at the end of each test function (where `x` is large enough to complete all animations). Otherwise, if any animation is left pending at the time that MockClock.dispose() is called, that will permanently prevent any future animations from playing on the page.
opt_autoInstall
{boolean
=}
.REQUEST_ANIMATION_FRAME_TIMEOUT
{number
}Default wait timeout for mocking requestAnimationFrame (in milliseconds).
.addOnDisposeCallback(callback, opt_scope)
Inherited from goog.Disposable
.
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
callback
{!Function
}
opt_scope
{Object
=}
.creationStack
{string
}Inherited from goog.Disposable
.
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
.dispose()
Inherited from goog.Disposable
.
Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
void
}
.disposeInternal()
[protected]Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend {@code goog.Disposable} should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' {@code disposeInternal} method. Everywhere else the public {@code dispose} method must be used. For example:
mypackage.MyClass = function() { goog.base(this); // Constructor logic specific to MyClass. ... }; goog.inherits(mypackage.MyClass, goog.Disposable); mypackage.MyClass.prototype.disposeInternal = function() { goog.base(this, 'disposeInternal'); // Dispose logic specific to MyClass. ... };
.getCurrentTime()
number
}
.getDisposed
[deprecated]Deprecated. Use {@link #isDisposed} instead.
Inherited from goog.Disposable
.
boolean
}
.getTimeoutDelay()
number
}
.getTimeoutsMade()
number
}
.install()
Installs the MockClock by overriding the global object's implementation of setTimeout, setInterval, clearTimeout and clearInterval.
.isDisposed()
Inherited from goog.Disposable
.
boolean
}
.isTimeoutSet(timeoutKey)
timeoutKey
{number
}
boolean
}
.registerDisposable(disposable)
Inherited from goog.Disposable
.
Associates a disposable object with this object so that they will be disposed together.
disposable
{goog.disposable.IDisposable
}
.reset()
Resets the MockClock, removing all timeouts that are scheduled and resets the fake timer count.
.setTimeoutDelay(delay)
Sets the amount of time between when a timeout is scheduled to fire and when it actually fires.
delay
{number
}
.tick(opt_millis)
Increments the MockClock's time by a given number of milliseconds, running any functions that are now overdue.
opt_millis
{number
=}
number
}
.uninstall()
Removes the MockClock's hooks into the global object's functions and revert to their original values.