goog.testing.DeferredTestCase
Provided By | |
---|---|
Extends |
warning Deprecated | Use goog.testing.TestCase instead. goog.testing.TestCase now supports async testing using promises. |
---|
A test case that can asynchronously wait on a Deferred object.
new DeferredTestCase( opt_name )
Parameters |
|
---|
Instance Methods
this.add( test ) → void
void
Adds a new test to the test case.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.addCompletedCallback( fn ) → void
void
Adds a callback function that should be executed when the tests have completed.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.addNewTest( name, ref, scope, objChain ) → void
void
Creates and adds a new test.
Convenience function to make syntax less awkward when not using automatic test discovery.
Defined by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.addWaitForAsync( msg, d ) → void
void
Adds a callback to update the wait message of this async test case. Using this method generously also helps to document the test flow.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
See Also |
this.autoDiscoverLifecycle() → void
void
Adds any functions defined on the global object that correspond to lifecycle events for the test case. Overrides setUp, tearDown, setUpPage, tearDownPage, runTests, and shouldRunTests if they are defined on global object.
this.autoDiscoverTests() → void
void
Adds any functions defined in the global scope that are prefixed with "test" to the test case.
this.clearTimeout( id ) → void
void
Clears a timeout created by this.timeout()
.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.continueTesting() → void
void
Continue with the next step in the test cycle.
this.createTest( name, ref, scope, objChain ) → goog.testing.TestCase.Test
goog.testing.TestCase.Test
Creates a goog.testing.TestCase.Test
from an auto-discovered
function.
Defined by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||||||||||
Returns |
|
this.cycleTests() → void
void
Starts the tests.
Defined by | |
---|---|
Overrides | |
Parameters | None. |
this.doAsyncError( opt_e ) → void
void
Handles an exception thrown by a test.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Throws |
|
this.doError( test ) → void
void
Handles a test that failed.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.doSkipped( test ) → void
void
Handles a test that was skipped.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.doSuccess( test ) → void
void
Handles a test that passed.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.enableDebugLogging() → void
void
Enables verbose logging of what is happening inside of the AsyncTestCase.
this.execute() → void
void
Executes the tests, yielding asynchronously if execution time exceeds
maxRunTime
. There is no guarantee that the test case has finished
once this method has returned. To be notified when the test case
has finished, use #addCompletedCallback
or
#runTestsReturningPromise
.
this.finalize() → void
void
Finalizes the test case, called when the tests have finished executing.
Defined by | |
---|---|
Overrides | |
Parameters | None. |
this.getActuallyRunCount() → number
number
Returns the number of tests actually run in the test case, i.e. subtracting any which are skipped.
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getAutoDiscoveryPrefix() → string
string
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getBatchTime() → number
number
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getCount() → number
number
Returns the number of tests contained in the test case.
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getCurrentStepName() → string
string
The current step name.
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getCurrentTest() → (goog.testing.TestCase.Test|null)
(goog.testing.TestCase.Test|null)
Returns the current test or null.
Defined by | ||
---|---|---|
Parameters | None. | |
Returns |
|
Gets list of objects that potentially contain test cases. For IE 8 and below, this is the global "this" (for properties set directly on the global this or window) and the RuntimeObject (for global variables and functions). For all other browsers, the array simply contains the global this.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.getName() → string
string
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getNumFilesLoaded() → number
number
Returns the number of script files that were loaded in order to run the test.
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getReport( opt_verbose ) → string
string
this.getResult() → goog.testing.TestCase.Result
goog.testing.TestCase.Result
Returns the test results.
Defined by | ||
---|---|---|
Parameters | None. | |
Returns |
|
this.getRunTime() → number
number
Returns the amount of time it took for the test to run.
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getTests() → Array<(goog.testing.TestCase.Test|null)>
Array<(goog.testing.TestCase.Test|null)>
Gets the tests.
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.groupLogsEnd() → void
void
Closes the group of the upcoming logs
this.groupLogsStart() → void
void
Groups the upcoming logs in the same log group
this.ignoreStartupCspViolations() → void
void
Call this from setUpPage() to prevent any Content Security Policy violations that may have occurred during page load from being reported as errors .
this.invalidateAssertionException( e ) → void
void
Removes the specified exception from being tracked. This only needs to be
called for internal functions that intentionally catch an exception, such
as
#assertThrowsJsUnitException
.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.isInsideMultiTestRunner() → boolean
boolean
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.isSuccess() → boolean
boolean
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.log( val ) → void
void
Logs an object to the console, if available.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.logError( name, error ) → goog.testing.TestCase.Error
goog.testing.TestCase.Error
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||
Returns |
|
this.maybeFailTestEarly( testCase ) → boolean
boolean
Checks to see if the test should be marked as failed before it is run.
If there was an error in setUpPage, we treat that as a failure for all tests and mark them all as having failed.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.next() → (goog.testing.TestCase.Test|null)
(goog.testing.TestCase.Test|null)
Returns the current test and increments the pointer.
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.now() → number
number
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.observeCspViolations( enable ) → void
void
Toggles recording of Content Security Policy violations. Call this with false during tests, setUpPage, setUp, and tearDown functions to prevent CSP violations occurring while the function is executing from being reported as errors. Reporting will be reset upon execution of the next test function.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.onError( err ) → void
void
this.onSuccess() → void
void
Handler for when the test succeeds.
this.raiseAssertionException( e ) → void
void
Makes note of an exception arising from an assertion, and then throws it. If the test otherwise passes (i.e., because something else caught the exception on its way to the test framework), it will be forced to fail.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Throws |
|
this.recordError( testName, error ) → void
void
Records and logs an error from or related to a test.
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.recordTestError( error ) → void
void
Records an error that fails the current test, without throwing it.
Use this function to implement expect()-style assertion libraries that fail a test without breaking execution (so you can see further failures). Do not use this from normal test code.
Please contact js-core-libraries-team@ before using this method. If it grows popular, we may add an expect() API to Closure.
NOTE: If there is no active TestCase, you must throw an error.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.reset() → void
void
Resets the test case pointer, so that next returns the first test.
this.runTests() → void
void
Sets up the test page and then waits until the test case has been marked as ready before executing the tests.
Defined by | |
---|---|
Overrides | |
Parameters | None. |
this.runTestsReturningPromise() → IThenable<goog.testing.TestCase.Result>
IThenable<goog.testing.TestCase.Result>
Executes each of the tests, returning a promise that resolves with the test results once they are done running.
Defined by | ||
---|---|---|
Parameters | None. | |
Returns |
|
this.saveMessage( message ) → void
void
Saves a message to the result set.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setBatchTime( batchTime ) → void
void
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setLifecycleObj( obj ) → void
void
Extracts any functions defined on 'obj' that correspond to page lifecycle events (setUpPage, tearDownPage, runTests, shouldRunTests) and add them to on this test case.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setOrder( order ) → void
void
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setTestDoneCallback( testDone ) → void
void
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setTestObj( obj ) → void
void
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setTests( tests ) → void
void
Sets the tests.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setTestsToRun( testsToRun ) → void
void
this.setUp() → ({then: ?}|undefined)
({then: ?}|undefined)
Gets called before every goog.testing.TestCase.Test is been executed. Can be overridden to add set up functionality to each test.
Defined by | ||
---|---|---|
Parameters | None. | |
Returns |
|
this.setUpPage() → ({then: ?}|undefined)
({then: ?}|undefined)
Gets called before any tests are executed. Can be overridden to set up the environment for the whole test case.
Defined by | ||
---|---|---|
Parameters | None. | |
Returns |
|
this.shouldLogTestProgress() → boolean
boolean
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.shouldRunTests() → boolean
boolean
Can be overridden in test classes to indicate whether the tests in a case should be run in that particular situation. For example, this could be used to stop tests running in a particular browser, where browser support for the class under test was absent.
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.signal() → void
void
Signals once to continue with the test. If this is the last signal that the test was waiting on, call continueTesting.
this.tearDown() → ({then: ?}|undefined)
({then: ?}|undefined)
Gets called after every goog.testing.TestCase.Test has been executed. Can be overridden to add tear down functionality to each test.
Defined by | ||
---|---|---|
Parameters | None. | |
Returns |
|
this.tearDownPage() → void
void
Gets called after all tests have been executed. Can be overridden to tear down the entire test case.
this.timeout( fn, time ) → number
number
this.useGoogPromise() → void
void
Configures the TestCase to use goog.Promise when waiting for methods that return Thenables.
this.useNativePromise() → void
void
Configures the TestCase to use native Promises when waiting for methods that return Thenables.
this.waitForAsync( opt_name ) → void
void
Informs the testcase not to continue to the next step in the test cycle until continueTesting is called.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.waitForDeferred( a, opt_b ) → void
void
Wires up given Deferred object to the test case, then starts the goog.async.Deferred object's callback.
Parameters |
|
---|
this.waitForSignals( times, opt_name ) → void
void
Informs the testcase not to continue to the next step in the test cycle until signal is called the specified number of times. Within a test, this function behaves additively if called multiple times; the number of signals to wait for will be the sum of all expected number of signals this function was called with.
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
Instance Properties
this.activeTest → (goog.testing.TestCase.Test|null|undefined)
(goog.testing.TestCase.Test|null|undefined)
The currently active test.
this.endTime_ → (number|undefined)
(number|undefined)
No information.
this.exceptionBeforeTest → *
*
Exception object that was detected before a test runs.
this.order → string
string
The order to run the auto-discovered tests in.
this.promiseTimeout → number
number
The maximum time in milliseconds a promise returned from a test function may remain pending before the test fails due to timeout.
this.result_ → goog.testing.TestCase.Result
goog.testing.TestCase.Result
Object used to encapsulate the test results.
this.running → boolean
boolean
Whether the test case is running.
this.started → boolean
boolean
Whether the test case has ever tried to execute.
this.stepTimeout → number
number
How long to wait for a single step of a test to complete in milliseconds. A step starts when a call to waitForAsync() is made.
this.timeToSleepAfterFailure → number
number
How long to wait after a failed test before moving onto the next one. The purpose of this is to allow any pending async callbacks from the failing test to finish up and not cause the next test to fail.
Static Functions
DeferredTestCase.createAndInstall( opt_name ) → goog.testing.DeferredTestCase
goog.testing.DeferredTestCase
Preferred way of creating a DeferredTestCase. Creates one and initializes it with the G_testRunner.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|