Version 3.17.2
Show:

Test.TestCase Class

Defined in: test/js/TestCase.js:1
Module: test

Test case containing various tests to run.

Item Index

Properties

Methods

_waitTimeout

() protected static

Calls YUITest.Assert.fail() with a message indicating wait() was called, but resume() was never called.

assert

(
  • condition
  • message
)

Asserts that a given condition is true. If not, then a YUITest.AssertionError object is thrown and the test fails.

Parameters:

  • condition Boolean

    The condition to test.

  • message String

    The message to display if the assertion fails.

callback

() Function

Method to call from an async init method to restart the test case. When called, returns a function that should be called when tests are ready to continue.

Returns:

Function:

The function to call as a callback.

destroy

()

Function to run once after tests finish running. This executes after the last call to tearDown().

fail

(
  • message
)

Forces an assertion error to occur. Shortcut for YUITest.Assert.fail().

Parameters:

  • message String

    (Optional) The message to display with the failure.

init

()

Function to run once before tests start to run. This executes before the first call to setUp().

next

(
  • callback
  • [context]
)
Function

Creates a callback that automatically resumes the test. Parameters as passed on to the callback.

Parameters:

  • callback Function

    Callback to call after resuming the test.

  • [context] Object optional

    The value of this inside the callback. If not given, the original context of the function will be used.

Returns:

Function:

wrapped callback that resumes the test.

Example:

// using test.resume()
Y.jsonp(uri, function (response) {
    test.resume(function () {
        Y.Assert.isObject(response);
    });
});
test.wait();

// using test.next()
Y.jsonp(uri, test.next(function (response) {
    Y.Assert.isObject(response);
}));
test.wait();

resume

(
  • segment
)

Resumes a paused test and runs the given function.

Parameters:

  • segment Function

    (Optional) The function to run. If omitted, the test automatically passes.

setUp

()

Function to run before each test is executed.

tearDown

()

Function to run after each test is executed.

wait

(
  • segment
  • delay
)

Causes the test case to wait a specified amount of time and then continue executing the given code.

Parameters:

  • segment Function

    (Optional) The function to run after the delay. If omitted, the TestRunner will wait until resume() is called.

  • delay Number

    (Optional) The number of milliseconds to wait before running the function. If omitted, defaults to DEFAULT_WAIT ms (10s).

waitFor

(
  • condition
  • segment
  • [timeout=10000]
  • [increment=100]
)

Delays the current test until condition returns a truthy value. If condition fails to return a truthy value before timeout milliseconds have passed, the test fails. Default timeout is 10s.

condition will be executed every increment milliseconds (default 100).

Parameters:

  • condition Function

    Function executed to indicate whether to execute segment

  • segment Function

    Function to check the success or failure of this test

  • [timeout=10000] Number optional

    Maximum number of milliseconds to wait for condition to return true

  • [increment=100] Number optional

    Milliseconds to wait before checking condition

Properties

DEFAULT_WAIT

Number static

Default delay for a test failure when wait() is called without a delay.

Default: 10000