⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yuitest_core-debug.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
/*Copyright (c) 2008, Yahoo! Inc. All rights reserved.Code licensed under the BSD License:http://developer.yahoo.net/yui/license.txtversion: 2.6.0*/YAHOO.namespace("tool");//-----------------------------------------------------------------------------// TestCase object//-----------------------------------------------------------------------------(function(){        //used for autogenerating test case names    var tempId = 0;        /**     * 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 TestCase     * @namespace YAHOO.tool     * @constructor     */    YAHOO.tool.TestCase = function (template /*:Object*/) {                /**         * 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 /*:Object*/ = {};                //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 (!YAHOO.lang.isString(this.name)){            /**             * Name for the test case.             */            this.name /*:String*/ = "testCase" + (tempId++);        }        };            YAHOO.tool.TestCase.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 /*:Function*/) /*:Void*/ {            YAHOO.tool.TestRunner.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 /*:Function*/, delay /*:int*/) /*:Void*/{            var args = arguments;            if (YAHOO.lang.isFunction(args[0])){                throw new YAHOO.tool.TestCase.Wait(args[0], args[1]);            } else {                throw new YAHOO.tool.TestCase.Wait(function(){                    YAHOO.util.Assert.fail("Timeout: wait() called but resume() never called.");                }, (YAHOO.lang.isNumber(args[0]) ? args[0] : 10000));            }                    },            //-------------------------------------------------------------------------        // Stub Methods        //-------------------------------------------------------------------------            /**         * Function to run before each test is executed.         * @return {Void}         * @method setUp         */        setUp : function () /*:Void*/ {        },                /**         * Function to run after each test is executed.         * @return {Void}         * @method tearDown         */        tearDown: function () /*:Void*/ {            }    };        /**     * 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 YAHOO.tool.TestCase     * @constructor     *     */    YAHOO.tool.TestCase.Wait = function (segment /*:Function*/, delay /*:int*/) {                /**         * The segment of code to run when the wait is over.         * @type Function         * @property segment         */        this.segment /*:Function*/ = (YAHOO.lang.isFunction(segment) ? segment : null);            /**         * The delay before running the segment of code.         * @type int         * @property delay         */        this.delay /*:int*/ = (YAHOO.lang.isNumber(delay) ? delay : 0);        };})();YAHOO.namespace("tool");//-----------------------------------------------------------------------------// TestSuite object//-----------------------------------------------------------------------------/** * A test suite that can contain a collection of TestCase and TestSuite objects. * @param {String||Object} data The name of the test suite or an object containing *      a name property as well as setUp and tearDown methods. * @namespace YAHOO.tool * @class TestSuite * @constructor */YAHOO.tool.TestSuite = function (data /*:String||Object*/) {    /**     * The name of the test suite.     * @type String     * @property name     */    this.name /*:String*/ = "";    /**     * Array of test suites and     * @private     */    this.items /*:Array*/ = [];    //initialize the properties    if (YAHOO.lang.isString(data)){        this.name = data;    } else if (YAHOO.lang.isObject(data)){        YAHOO.lang.augmentObject(this, data, true);    }    //double-check name    if (this.name === ""){        this.name = YAHOO.util.Dom.generateId(null, "testSuite");    }};YAHOO.tool.TestSuite.prototype = {        /**     * Adds a test suite or test case to the test suite.     * @param {YAHOO.tool.TestSuite||YAHOO.tool.TestCase} testObject The test suite or test case to add.     * @return {Void}     * @method add     */    add : function (testObject /*:YAHOO.tool.TestSuite*/) /*:Void*/ {        if (testObject instanceof YAHOO.tool.TestSuite || testObject instanceof YAHOO.tool.TestCase) {            this.items.push(testObject);        }    },        //-------------------------------------------------------------------------    // Stub Methods    //-------------------------------------------------------------------------    /**     * Function to run before each test is executed.     * @return {Void}     * @method setUp     */    setUp : function () /*:Void*/ {    },        /**     * Function to run after each test is executed.     * @return {Void}     * @method tearDown     */    tearDown: function () /*:Void*/ {    }    };YAHOO.namespace("tool");/** * The YUI test tool * @module yuitest * @namespace YAHOO.tool * @requires yahoo,dom,event,logger *///-----------------------------------------------------------------------------// TestRunner object//-----------------------------------------------------------------------------YAHOO.tool.TestRunner = (function(){    /**     * A node in the test tree structure. May represent a TestSuite, TestCase, or     * test function.     * @param {Variant} testObject A TestSuite, TestCase, or the name of a test function.     * @class TestNode     * @constructor     * @private     */    function TestNode(testObject /*:Variant*/){            /**         * The TestSuite, TestCase, or test function represented by this node.         * @type Variant         * @property testObject         */        this.testObject = testObject;                /**         * Pointer to this node's first child.         * @type TestNode         * @property firstChild         */                this.firstChild /*:TestNode*/ = null;                /**         * Pointer to this node's last child.         * @type TestNode         * @property lastChild         */                this.lastChild = null;                /**         * Pointer to this node's parent.         * @type TestNode         * @property parent         */                this.parent = null;            /**         * Pointer to this node's next sibling.         * @type TestNode         * @property next         */                this.next = null;                /**         * Test results for this test object.         * @type object         * @property results         */                        this.results /*:Object*/ = {            passed : 0,            failed : 0,            total : 0,            ignored : 0        };                //initialize results        if (testObject instanceof YAHOO.tool.TestSuite){            this.results.type = "testsuite";            this.results.name = testObject.name;        } else if (testObject instanceof YAHOO.tool.TestCase){            this.results.type = "testcase";            this.results.name = testObject.name;        }           }        TestNode.prototype = {            /**         * Appends a new test object (TestSuite, TestCase, or test function name) as a child         * of this node.         * @param {Variant} testObject A TestSuite, TestCase, or the name of a test function.         * @return {Void}         */        appendChild : function (testObject /*:Variant*/) /*:Void*/{            var node = new TestNode(testObject);            if (this.firstChild === null){                this.firstChild = this.lastChild = node;            } else {                this.lastChild.next = node;                this.lastChild = node;            }            node.parent = this;            return node;        }           };    /**     * Runs test suites and test cases, providing events to allowing for the     * interpretation of test results.     * @namespace YAHOO.tool     * @class TestRunner     * @static     */    function TestRunner(){            //inherit from EventProvider        TestRunner.superclass.constructor.apply(this,arguments);                /**         * Suite on which to attach all TestSuites and TestCases to be run.         * @type YAHOO.tool.TestSuite         * @property masterSuite         * @private         * @static         */        this.masterSuite /*:YAHOO.tool.TestSuite*/ = new YAHOO.tool.TestSuite("YUI Test Results");                /**         * Pointer to the current node in the test tree.         * @type TestNode         * @private         * @property _cur         * @static         */        this._cur = null;                /**         * Pointer to the root node in the test tree.         * @type TestNode         * @private         * @property _root         * @static         */        this._root = null;                //create events        var events /*:Array*/ = [            this.TEST_CASE_BEGIN_EVENT,            this.TEST_CASE_COMPLETE_EVENT,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -