Jump to Table of Contents

Test Console

Test Console is a specialized subclass of the Console widget that's pre-configured to display YUI Test output in an attractive, readable log with no extra configuration needed. Just drop it into your test page and run your tests!

Getting Started

To include the source files for Test Console and its dependencies, first load the YUI seed file if you haven't already loaded it.

<script src="http://yui.yahooapis.com/3.8.0/build/yui/yui-min.js"></script>

Next, create a new YUI instance for your application and populate it with the modules you need by specifying them as arguments to the YUI().use() method. YUI will automatically load any dependencies required by the modules you specify.

<script>
// Create a new YUI instance and populate it with the required modules.
YUI().use('test-console', function (Y) {
    // Test Console is available and ready for use. Add implementation
    // code here.
});
</script>

For more information on creating YUI instances and on the use() method, see the documentation for the YUI Global Object.

Using Test Console

First, create some tests using YUI Test. Next, create a Test Console instance on your test page and run your tests.

<div id="log" class="yui3-skin-sam"></div>

<script>
YUI().use('test-console', function (Y) {
    // ... set up your test cases here ...

    // Render the console inside the #log div, then run the tests.
    new Y.Test.Console().render('#log');
    Y.Test.Runner.run();
});
</script>

Test results will automatically be displayed in the test console. By default, only failing tests and the final summary info will be displayed to keep things readable. If you'd like to see an entry for passing tests as well, just click the "pass" checkbox at the bottom of the console.

Category Filters

The Test Console supports filtering of the entries it displays. By default, failing tests and a final summary are always displayed, while passing tests and other status information are hidden to avoid clutter.

You can change which categories are displayed or hidden by passing a custom configuration for the filters attribute.

// Show passing tests as well as failing tests by default.
new Y.Test.Console({
    filters: {
        pass: true,
        fail: true
    }
}).render();

The following entry categories are available.

Category Default Description
fail true

A failing test.

info true

Summary information displayed after all tests have run, such as the total number of passing and failing tests.

pass false

A passing test.

status false

Status information displayed after each test case has run. This can be noisy when running a test suite with many test cases, so it's disabled by default.

Demo

Here's a working example you can play with. Try checking the "pass" checkbox to see passing tests.