goog.testing.ContinuationTestCase
Provided By | |
---|---|
Extends |
warning Deprecated | ContinuationTestCase is deprecated. Prefer returning Promises for tests that assert Asynchronous behavior. |
---|
Constructs a test case that supports tests with continuations. Test functions may issue "wait" commands that suspend the test temporarily and continue once the wait condition is met.
new ContinuationTestCase( 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.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.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
Cycles through the tests, yielding asynchronously if the execution time
exceeds #maxRunTime
. In particular, there is no guarantee that
the test case has finished execution once this method has returned.
To be notified when the test case has finished execution, use
#addCompletedCallback
or #runTestsReturningPromise
.
Overrides | |
---|---|
Parameters | None. |
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.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.
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.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.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
Executes each of the tests, yielding asynchronously if execution time
exceeds #maxRunTime
. There is no guarantee that the test case
has finished execution once this method has returned.
To be notified when the test case has finished execution, use
#addCompletedCallback
or #runTestsReturningPromise
.
Overridable by the individual test case. This allows test cases to defer when the test is actually started. If overridden, finalize must be called by the test to indicate it has finished.
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.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.waitForCondition( condition, continuation, opt_interval, opt_maxTimeout ) → void
void
Creates a new test step which will run once a condition becomes true. The condition will be polled at a user-specified interval until it becomes true, or until a maximum timeout is reached.
Parameters |
|
---|
this.waitForEvent( eventTarget, eventType, continuation ) → void
void
Creates a new test step that will run after an event has fired. If the event does not fire within a reasonable timeout, the test will fail.
Parameters |
|
---|
this.waitForTimeout( continuation, opt_duration ) → void
void
Creates a new test step that will run after a user-specified timeout. No guarantee is made on the execution order of the continuation, except for those provided by each browser's window.setTimeout. In particular, if two continuations are registered at the same time with very small delta for their durations, this class can not guarantee that the continuation with the smaller duration will be executed first.
Parameters |
|
---|
Instance Properties
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.
Static Properties
ContinuationTestCase.MAX_TIMEOUT → number
number
The default maximum time to wait for a single test step in milliseconds.