# Yahoo! UI Library

### test 3.0.0

Yahoo! UI Library > test > TestCase.js (source view)
Search:
Filters Show Private Show Protected Show Deprecated

        /**
         * YUI JavaScript Testing Framework
         *
         * @module test
         */

        Y.namespace("Test");

        /**
         * Test case containing various tests to run.
         * @param template An object containing any number of test methods, other methods,
         *                 an optional name, and anything else the test case needs.
         * @class Case
         * @namespace Test
         * @constructor
         */
        Y.Test.Case = function (template) {

            /**
             * Special rules for the test case. Possible subobjects
             * are fail, for tests that should fail, and error, for
             * tests that should throw an error.
             */
            this._should = {};

            //copy over all properties from the template to this object
            for (var prop in template) {
                this[prop] = template[prop];
            }

            //check for a valid name
            if (!Y.Lang.isString(this.name)){
                /**
                 * Name for the test case.
                 */
                this.name = "testCase" + Y.guid();
            }

        };

        Y.Test.Case.prototype = {

            /**
             * Resumes a paused test and runs the given function.
             * @param {Function} segment (Optional) The function to run.
             *      If omitted, the test automatically passes.
             * @return {Void}
             * @method resume
             */
            resume : function (segment) {
                Y.Test.Runner.resume(segment);
            },

            /**
             * Causes the test case to wait a specified amount of time and then
             * continue executing the given code.
             * @param {Function} segment (Optional) The function to run after the delay.
             *      If omitted, the TestRunner will wait until resume() is called.
             * @param {int} delay (Optional) The number of milliseconds to wait before running
             *      the function. If omitted, defaults to zero.
             * @return {Void}
             * @method wait
             */
            wait : function (segment, delay){
                var args = arguments;
                if (Y.Lang.isFunction(args[0])){
                    throw new Y.Test.Wait(args[0], args[1]);
                } else {
                    throw new Y.Test.Wait(function(){
                        Y.Assert.fail("Timeout: wait() called but resume() never called.");
                    }, (Y.Lang.isNumber(args[0]) ? args[0] : 10000));
                }
            },

            //-------------------------------------------------------------------------
            // Stub Methods
            //-------------------------------------------------------------------------

            /**
             * Function to run before each test is executed.
             * @return {Void}
             * @method setUp
             */
            setUp : function () {
            },

            /**
             * Function to run after each test is executed.
             * @return {Void}
             * @method tearDown
             */
            tearDown: function () {
            }
        };

        /**
         * Represents a stoppage in test execution to wait for an amount of time before
         * continuing.
         * @param {Function} segment A function to run when the wait is over.
         * @param {int} delay The number of milliseconds to wait before running the code.
         * @class Wait
         * @namespace Test
         * @constructor
         *
         */
        Y.Test.Wait = function (segment, delay) {

            /**
             * The segment of code to run when the wait is over.
             * @type Function
             * @property segment
             */
            this.segment = (Y.Lang.isFunction(segment) ? segment : null);

            /**
             * The delay before running the segment of code.
             * @type int
             * @property delay
             */
            this.delay = (Y.Lang.isNumber(delay) ? delay : 0);
        };

Copyright © 2009 Yahoo! Inc. All rights reserved.