test-debug.js revision af3ee734c3099cd0ac6ece4fbf2c15c173a6c55e
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncYUI.add('test', function(Y) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * YUI JavaScript Testing Framework
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @module yuitest
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.namespace("Test");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Test case containing various tests to run.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param template An object containing any number of test methods, other methods,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * an optional name, and anything else the test case needs.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @class Case
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @namespace Test
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @constructor
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Test.Case = function (template /*:Object*/) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Special rules for the test case. Possible subobjects
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * are fail, for tests that should fail, and error, for
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * tests that should throw an error.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._should /*:Object*/ = {};
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //copy over all properties from the template to this object
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (var prop in template) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this[prop] = template[prop];
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //check for a valid name
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!Y.Lang.isString(this.name)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Name for the test case.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.name /*:String*/ = "testCase" + Y.guid();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Test.Case.prototype = {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Resumes a paused test and runs the given function.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Function} segment (Optional) The function to run.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * If omitted, the test automatically passes.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method resume
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync resume : function (segment /*:Function*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Test.Runner.resume(segment);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
dbec828311ed2a5cf6fbc68fe4391d516ba4f92fvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Causes the test case to wait a specified amount of time and then
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * continue executing the given code.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Function} segment (Optional) The function to run after the delay.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * If omitted, the TestRunner will wait until resume() is called.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {int} delay (Optional) The number of milliseconds to wait before running
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * the function. If omitted, defaults to zero.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method wait
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync wait : function (segment /*:Function*/, delay /*:int*/) /*:Void*/{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var args = arguments;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (Y.Lang.isFunction(args[0])){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Test.Wait(args[0], args[1]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Test.Wait(function(){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert.fail("Timeout: wait() called but resume() never called.");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }, (Y.Lang.isNumber(args[0]) ? args[0] : 10000));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Stub Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * Function to run before each test is executed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method setUp
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync setUp : function () /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Function to run after each test is executed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method tearDown
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync tearDown: function () /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Represents a stoppage in test execution to wait for an amount of time before
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * continuing.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Function} segment A function to run when the wait is over.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {int} delay The number of milliseconds to wait before running the code.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @class Wait
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @namespace Test
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @constructor
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Test.Wait = function (segment /*:Function*/, delay /*:int*/) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * The segment of code to run when the wait is over.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type Function
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property segment
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.segment /*:Function*/ = (Y.Lang.isFunction(segment) ? segment : null);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * The delay before running the segment of code.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type int
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property delay
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.delay /*:int*/ = (Y.Lang.isNumber(delay) ? delay : 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.namespace("Test");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * A test suite that can contain a collection of TestCase and TestSuite objects.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String||Object} data The name of the test suite or an object containing
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * a name property as well as setUp and tearDown methods.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @namespace Test
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @class Suite
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @constructor
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Test.Suite = function (data /*:String||Object*/) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * The name of the test suite.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type String
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property name
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.name /*:String*/ = "";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Array of test suites and
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.items /*:Array*/ = [];
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //initialize the properties
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (Y.Lang.isString(data)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.name = data;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else if (Y.Lang.isObject(data)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.mix(this, data, true);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //double-check name
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (this.name === ""){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.name = "testSuite" + Y.guid();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Test.Suite.prototype = {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Adds a test suite or test case to the test suite.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Y.Test.Suite||Y.Test.Case} testObject The test suite or test case to add.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method add
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync add : function (testObject /*:Y.Test.Suite*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (testObject instanceof Y.Test.Suite || testObject instanceof Y.Test.Case) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.items.push(testObject);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Stub Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Function to run before each test is executed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method setUp
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync setUp : function () /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Function to run after each test is executed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method tearDown
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync tearDown: function () /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /*
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Runs test suites and test cases, providing events to allowing for the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * interpretation of test results.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @namespace Test
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @class Runner
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Test.Runner = (function(){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * A node in the test tree structure. May represent a TestSuite, TestCase, or
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * test function.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Variant} testObject A TestSuite, TestCase, or the name of a test function.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @class TestNode
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @constructor
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync function TestNode(testObject /*:Variant*/){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * The TestSuite, TestCase, or test function represented by this node.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type Variant
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property testObject
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.testObject = testObject;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Pointer to this node's first child.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type TestNode
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property firstChild
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.firstChild /*:TestNode*/ = null;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Pointer to this node's last child.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type TestNode
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property lastChild
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.lastChild = null;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Pointer to this node's parent.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type TestNode
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property parent
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.parent = null;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Pointer to this node's next sibling.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type TestNode
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property next
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.next = null;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Test results for this test object.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type object
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property results
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.results /*:Object*/ = {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync passed : 0,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync failed : 0,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync total : 0,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ignored : 0
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //initialize results
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (testObject instanceof Y.Test.Suite){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.results.type = "testsuite";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.results.name = testObject.name;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else if (testObject instanceof Y.Test.Case){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.results.type = "testcase";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.results.name = testObject.name;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TestNode.prototype = {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Appends a new test object (TestSuite, TestCase, or test function name) as a child
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * of this node.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Variant} testObject A TestSuite, TestCase, or the name of a test function.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync appendChild : function (testObject /*:Variant*/) /*:Void*/{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var node = new TestNode(testObject);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (this.firstChild === null){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.firstChild = this.lastChild = node;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.lastChild.next = node;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.lastChild = node;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent = this;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return node;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Runs test suites and test cases, providing events to allowing for the
11c2b573e2625474a51ae55ee1f3f82936f125davboxsync * interpretation of test results.
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @namespace Test
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @class Runner
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync function TestRunner(){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //inherit from EventProvider
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TestRunner.superclass.constructor.apply(this,arguments);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Suite on which to attach all TestSuites and TestCases to be run.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type Y.Test.Suite
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property masterSuite
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.masterSuite /*:Y.Test.Suite*/ = new Y.Test.Suite("YUI Test Results");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Pointer to the current node in the test tree.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type TestNode
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property _cur
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._cur = null;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Pointer to the root node in the test tree.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type TestNode
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property _root
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._root = null;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Indicates if the TestRunner will log events or not.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type Boolean
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property _log
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._log = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //create events
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var events = [
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.TEST_CASE_BEGIN_EVENT,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.TEST_CASE_COMPLETE_EVENT,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.TEST_SUITE_BEGIN_EVENT,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.TEST_SUITE_COMPLETE_EVENT,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.TEST_PASS_EVENT,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.TEST_FAIL_EVENT,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.TEST_IGNORE_EVENT,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.COMPLETE_EVENT,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.BEGIN_EVENT
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ];
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (var i=0; i < events.length; i++){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.subscribe(events[i], this._logEvent, this, true);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.extend(TestRunner, Y.Event.Target, {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Constants
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Fires when a test case is opened but before the first
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * test is executed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @event testcasebegin
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TEST_CASE_BEGIN_EVENT /*:String*/ : "testcasebegin",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Fires when all tests in a test case have been executed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @event testcasecomplete
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TEST_CASE_COMPLETE_EVENT /*:String*/ : "testcasecomplete",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Fires when a test suite is opened but before the first
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * test is executed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @event testsuitebegin
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TEST_SUITE_BEGIN_EVENT /*:String*/ : "testsuitebegin",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Fires when all test cases in a test suite have been
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * completed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @event testsuitecomplete
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TEST_SUITE_COMPLETE_EVENT /*:String*/ : "testsuitecomplete",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Fires when a test has passed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @event pass
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TEST_PASS_EVENT /*:String*/ : "pass",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Fires when a test has failed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @event fail
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TEST_FAIL_EVENT /*:String*/ : "fail",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Fires when a test has been ignored.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @event ignore
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TEST_IGNORE_EVENT /*:String*/ : "ignore",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Fires when all test suites and test cases have been completed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @event complete
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync COMPLETE_EVENT /*:String*/ : "complete",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Fires when the run() method is called.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @event begin
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync * @static
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync */
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync BEGIN_EVENT /*:String*/ : "begin",
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Logging-Related Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Disable logging via Y.log(). Test output will not be visible unless
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * TestRunner events are subscribed to.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method disableLogging
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync disableLogging: function(){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._log = false;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync },
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync /**
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * Enable logging via Y.log(). Test output is published and can be read via
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * logreader.
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @return {Void}
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @method enableLogging
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @static
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync */
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync enableLogging: function(){
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync this._log = true;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Logs TestRunner events using Y.log().
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @param {Object} event The event object for the event.
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @return {Void}
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @method _logEvent
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @private
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @static
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync */
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync _logEvent: function(event){
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync //data variables
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync var message /*:String*/ = "";
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync var messageType /*:String*/ = "";
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync switch(event.type){
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync case this.BEGIN_EVENT:
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync message = "Testing began at " + (new Date()).toString() + ".";
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync messageType = "info";
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync break;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync case this.COMPLETE_EVENT:
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync message = "Testing completed at " + (new Date()).toString() + ".\nPassed:" +
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync event.results.passed + " Failed:" + event.results.failed + " Total:" + event.results.total;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync messageType = "info";
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case this.TEST_FAIL_EVENT:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message = event.testName + ": " + event.error.getMessage();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync messageType = "fail";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case this.TEST_IGNORE_EVENT:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message = event.testName + ": ignored.";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync messageType = "ignore";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case this.TEST_PASS_EVENT:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message = event.testName + ": passed.";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync messageType = "pass";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case this.TEST_SUITE_BEGIN_EVENT:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message = "Test suite \"" + event.testSuite.name + "\" started.";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync messageType = "info";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case this.TEST_SUITE_COMPLETE_EVENT:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message = "Test suite \"" + event.testSuite.name + "\" completed.\nPassed:" +
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync event.results.passed + " Failed:" + event.results.failed + " Total:" + event.results.total;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync messageType = "info";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case this.TEST_CASE_BEGIN_EVENT:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message = "Test case \"" + event.testCase.name + "\" started.";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync messageType = "info";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync case this.TEST_CASE_COMPLETE_EVENT:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message = "Test case \"" + event.testCase.name + "\" completed.\nPassed:" +
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync event.results.passed + " Failed:" + event.results.failed + " Total:" + event.results.total;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync messageType = "info";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync break;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync default:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message = "Unexpected event " + event.type;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message = "info";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //only log if required
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (this._log){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.log(message, messageType, "TestRunner");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Test Tree-Related Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Adds a test case to the test tree as a child of the specified node.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {TestNode} parentNode The node to add the test case to as a child.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Y.Test.Case} testCase The test case to add.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method _addTestCaseToTestTree
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync _addTestCaseToTestTree : function (parentNode /*:TestNode*/, testCase /*:Y.Test.Case*/) /*:Void*/{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //add the test suite
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var node = parentNode.appendChild(testCase);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //iterate over the items in the test case
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (var prop in testCase){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (prop.indexOf("test") === 0 && Y.Lang.isFunction(testCase[prop])){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.appendChild(prop);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Adds a test suite to the test tree as a child of the specified node.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {TestNode} parentNode The node to add the test suite to as a child.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Y.Test.Suite} testSuite The test suite to add.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method _addTestSuiteToTestTree
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync _addTestSuiteToTestTree : function (parentNode /*:TestNode*/, testSuite /*:Y.Test.Suite*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //add the test suite
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var node = parentNode.appendChild(testSuite);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //iterate over the items in the master suite
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (var i=0; i < testSuite.items.length; i++){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (testSuite.items[i] instanceof Y.Test.Suite) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._addTestSuiteToTestTree(node, testSuite.items[i]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else if (testSuite.items[i] instanceof Y.Test.Case) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._addTestCaseToTestTree(node, testSuite.items[i]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Builds the test tree based on items in the master suite. The tree is a hierarchical
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * representation of the test suites, test cases, and test functions. The resulting tree
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * is stored in _root and the pointer _cur is set to the root initially.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method _buildTestTree
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync _buildTestTree : function () /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._root = new TestNode(this.masterSuite);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._cur = this._root;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //iterate over the items in the master suite
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (var i=0; i < this.masterSuite.items.length; i++){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (this.masterSuite.items[i] instanceof Y.Test.Suite) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._addTestSuiteToTestTree(this._root, this.masterSuite.items[i]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else if (this.masterSuite.items[i] instanceof Y.Test.Case) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._addTestCaseToTestTree(this._root, this.masterSuite.items[i]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Private Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Handles the completion of a test object's tests. Tallies test results
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * from one level up to the next.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {TestNode} node The TestNode representing the test object.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method _handleTestObjectComplete
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync _handleTestObjectComplete : function (node /*:TestNode*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (Y.Lang.isObject(node.testObject)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent.results.passed += node.results.passed;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent.results.failed += node.results.failed;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent.results.total += node.results.total;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent.results.ignored += node.results.ignored;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent.results[node.testObject.name] = node.results;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (node.testObject instanceof Y.Test.Suite){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.testObject.tearDown();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.fire(this.TEST_SUITE_COMPLETE_EVENT, { testSuite: node.testObject, results: node.results});
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else if (node.testObject instanceof Y.Test.Case){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.fire(this.TEST_CASE_COMPLETE_EVENT, { testCase: node.testObject, results: node.results});
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Navigation Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Retrieves the next node in the test tree.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {TestNode} The next node in the test tree or null if the end is reached.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method _next
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync _next : function () /*:TestNode*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (this._cur.firstChild) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._cur = this._cur.firstChild;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else if (this._cur.next) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._cur = this._cur.next;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync while (this._cur && !this._cur.next && this._cur !== this._root){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._handleTestObjectComplete(this._cur);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._cur = this._cur.parent;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (this._cur == this._root){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._cur.results.type = "report";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._cur.results.timestamp = (new Date()).toLocaleString();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._cur.results.duration = (new Date()) - this._cur.results.duration;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.fire(this.COMPLETE_EVENT, { results: this._cur.results});
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._cur = null;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._handleTestObjectComplete(this._cur);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._cur = this._cur.next;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return this._cur;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Runs a test case or test suite, returning the results.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Y.Test.Case|Y.Test.Suite} testObject The test case or test suite to run.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Object} Results of the execution with properties passed, failed, and total.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method _run
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync _run : function () /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //flag to indicate if the TestRunner should wait before continuing
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var shouldWait /*:Boolean*/ = false;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //get the next test node
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var node = this._next();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (node !== null) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var testObject = node.testObject;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //figure out what to do
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (Y.Lang.isObject(testObject)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (testObject instanceof Y.Test.Suite){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.fire(this.TEST_SUITE_BEGIN_EVENT, { testSuite: testObject });
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync testObject.setUp();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else if (testObject instanceof Y.Test.Case){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.fire(this.TEST_CASE_BEGIN_EVENT, { testCase: testObject });
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync //some environments don't support setTimeout
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync if (typeof setTimeout != "undefined"){
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync setTimeout(function(){
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync Y.Test.Runner._run();
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync }, 0);
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync } else {
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync this._run();
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync }
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync } else {
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync this._runTest(node);
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync }
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync }
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync },
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync _resumeTest : function (segment /*:Function*/) /*:Void*/ {
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync //get relevant information
dbec828311ed2a5cf6fbc68fe4391d516ba4f92fvboxsync var node /*:TestNode*/ = this._cur;
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync //if there's no node, it probably means a wait() was called after resume()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!node){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //TODO: Handle in some way?
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //console.log("wait() called after resume()");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //this.fire("error", { testCase: "(unknown)", test: "(unknown)", error: new Error("wait() called after resume()")} );
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var testName /*:String*/ = node.testObject;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var testCase /*:Y.Test.Case*/ = node.parent.testObject;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //cancel other waits if available
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (testCase.__yui_wait){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync clearTimeout(testCase.__yui_wait);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync delete testCase.__yui_wait;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //get the "should" test cases
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var shouldFail /*:Object*/ = (testCase._should.fail || {})[testName];
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var shouldError /*:Object*/ = (testCase._should.error || {})[testName];
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //variable to hold whether or not the test failed
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var failed /*:Boolean*/ = false;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var error /*:Error*/ = null;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //try the test
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync try {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //run the test
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync segment.apply(testCase);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //if it should fail, and it got here, then it's a fail because it didn't
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (shouldFail){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync error = new Y.Assert.ShouldFail();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync failed = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else if (shouldError){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync error = new Y.Assert.ShouldError();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync failed = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } catch (thrown /*:Error*/){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //cancel any pending waits, the test already failed
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (testCase.__yui_wait){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync clearTimeout(testCase.__yui_wait);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync delete testCase.__yui_wait;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //figure out what type of error it was
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (thrown instanceof Y.Assert.Error) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!shouldFail){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync error = thrown;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync failed = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else if (thrown instanceof Y.Test.Wait){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (Y.Lang.isFunction(thrown.segment)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (Y.Lang.isNumber(thrown.delay)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //some environments don't support setTimeout
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (typeof setTimeout != "undefined"){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync testCase.__yui_wait = setTimeout(function(){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Test.Runner._resumeTest(thrown.segment);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }, thrown.delay);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Error("Asynchronous tests not supported in this environment.");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //first check to see if it should error
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!shouldError) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync error = new Y.Assert.UnexpectedError(thrown);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync failed = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //check to see what type of data we have
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (Y.Lang.isString(shouldError)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //if it's a string, check the error message
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (thrown.message != shouldError){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync error = new Y.Assert.UnexpectedError(thrown);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync failed = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else if (Y.Lang.isFunction(shouldError)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //if it's a function, see if the error is an instance of it
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!(thrown instanceof shouldError)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync error = new Y.Assert.UnexpectedError(thrown);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync failed = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else if (Y.Lang.isObject(shouldError)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //if it's an object, check the instance and message
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!(thrown instanceof shouldError.constructor) ||
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync thrown.message != shouldError.message){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync error = new Y.Assert.UnexpectedError(thrown);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync failed = true;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //fire appropriate event
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (failed) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.fire(this.TEST_FAIL_EVENT, { testCase: testCase, testName: testName, error: error });
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.fire(this.TEST_PASS_EVENT, { testCase: testCase, testName: testName });
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //run the tear down
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync testCase.tearDown();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //update results
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent.results[testName] = {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync result: failed ? "fail" : "pass",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message: error ? error.getMessage() : "Test passed",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync type: "test",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync name: testName
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (failed){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent.results.failed++;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync node.parent.results.passed++;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent.results.total++;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //set timeout not supported in all environments
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (typeof setTimeout != "undefined"){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync setTimeout(function(){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Test.Runner._run();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }, 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._run();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Runs a single test based on the data provided in the node.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {TestNode} node The TestNode representing the test to run.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @name _runTest
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync _runTest : function (node /*:TestNode*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //get relevant information
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var testName /*:String*/ = node.testObject;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var testCase /*:Y.Test.Case*/ = node.parent.testObject;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var test /*:Function*/ = testCase[testName];
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //get the "should" test cases
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var shouldIgnore /*:Object*/ = (testCase._should.ignore || {})[testName];
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync //figure out if the test should be ignored or not
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync if (shouldIgnore){
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync //update results
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent.results[testName] = {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync result: "ignore",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message: "Test ignored",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync type: "test",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync name: testName
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent.results.ignored++;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync node.parent.results.total++;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.fire(this.TEST_IGNORE_EVENT, { testCase: testCase, testName: testName });
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //some environments don't support setTimeout
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (typeof setTimeout != "undefined"){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync setTimeout(function(){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Test.Runner._run();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }, 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._run();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } else {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //run the setup
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync testCase.setUp();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //now call the body of the test
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._resumeTest(test);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Protected Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /*
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Fires events for the TestRunner. This overrides the default fire()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * method from EventProvider to add the type property to the data that is
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * passed through on each event call.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} type The type of event to fire.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} data (Optional) Data for the event.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method fire
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @protected
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync fire : function (type /*:String*/, data /*:Object*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync data = data || {};
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync data.type = type;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TestRunner.superclass.fire.call(this, type, data);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Public Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Adds a test suite or test case to the list of test objects to run.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param testObject Either a TestCase or a TestSuite that should be run.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method add
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync add : function (testObject /*:Object*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.masterSuite.add(testObject);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Removes all test objects from the runner.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method clear
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync clear : function () /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.masterSuite.items = [];
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Resumes the TestRunner after wait() was called.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Function} segment The function to run as the rest
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * of the haulted test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method resume
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync resume : function (segment /*:Function*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this._resumeTest(segment || function(){});
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Runs the test suite.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {Void}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method run
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync run : function (testObject /*:Object*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //pointer to runner to avoid scope issues
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync var runner = Y.Test.Runner;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //build the test tree
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync runner._buildTestTree();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //set when the test started
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync runner._root.results.duration = (new Date()).valueOf();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //fire the begin event
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync runner.fire(runner.BEGIN_EVENT);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //begin the testing
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync runner._run();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync });
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return new TestRunner();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync })();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * The Assert object provides functions to test JavaScript values against
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * known and expected results. Whenever a comparison (assertion) fails,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * an error is thrown.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @class Assert
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert = {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * The number of assertions performed.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property _asserts
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync * @type int
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @private
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync _asserts: 0,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync // Helper Methods
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync //-------------------------------------------------------------------------
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync /**
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * Formats a message so that it can contain the original assertion message
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * in addition to the custom message.
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @param {String} customMessage The message passed in by the developer.
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @param {String} defaultMessage The message created by the error by default.
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @return {String} The final error message, containing either or both.
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @protected
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @static
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @method _formatMessage
11c2b573e2625474a51ae55ee1f3f82936f125davboxsync */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync _formatMessage : function (customMessage /*:String*/, defaultMessage /*:String*/) /*:String*/ {
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync var message = customMessage;
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync if (Y.Lang.isString(customMessage) && customMessage.length > 0){
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync return Y.Lang.substitute(customMessage, { message: defaultMessage });
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync } else {
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync return defaultMessage;
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync }
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync },
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync /**
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * Returns the number of assertions that have been performed.
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @method _getCount
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @protected
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @static
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync _getCount: function(){
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync return this._asserts;
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync },
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync /**
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * Increments the number of assertions that have been performed.
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @method _increment
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @protected
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @static
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync _increment: function(){
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync this._asserts++;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Resets the number of assertions that have been performed to 0.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method _reset
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @protected
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync */
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync _reset: function(){
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync this._asserts = 0;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync },
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync //-------------------------------------------------------------------------
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync // Generic Assertion Methods
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync //-------------------------------------------------------------------------
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync /**
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * Forces an assertion error to occur.
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @param {String} message (Optional) The message to display with the failure.
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @method fail
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * @static
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync fail : function (message /*:String*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.Error(Y.Assert._formatMessage(message, "Test force-failed."));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Equality Assertion Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is equal to another. This uses the double equals sign
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * so type cohersion may occur.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} expected The expected value.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The actual value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method areEqual
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync areEqual : function (expected /*:Object*/, actual /*:Object*/, message /*:String*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (expected != actual) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Values should be equal."), expected, actual);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is not equal to another. This uses the double equals sign
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * so type cohersion may occur.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} unexpected The unexpected value.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The actual value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method areNotEqual
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync areNotEqual : function (unexpected /*:Object*/, actual /*:Object*/,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync message /*:String*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (unexpected == actual) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.UnexpectedValue(Y.Assert._formatMessage(message, "Values should not be equal."), unexpected);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is not the same as another. This uses the triple equals sign
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * so no type cohersion may occur.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} unexpected The unexpected value.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The actual value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method areNotSame
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync areNotSame : function (unexpected /*:Object*/, actual /*:Object*/, message /*:String*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (unexpected === actual) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.UnexpectedValue(Y.Assert._formatMessage(message, "Values should not be the same."), unexpected);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is the same as another. This uses the triple equals sign
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * so no type cohersion may occur.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} expected The expected value.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The actual value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method areSame
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync areSame : function (expected /*:Object*/, actual /*:Object*/, message /*:String*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (expected !== actual) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Values should be the same."), expected, actual);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Boolean Assertion Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is false. This uses the triple equals sign
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * so no type cohersion may occur.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The actual value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isFalse
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isFalse : function (actual /*:Boolean*/, message /*:String*/) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (false !== actual) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Value should be false."), false, actual);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is true. This uses the triple equals sign
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * so no type cohersion may occur.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The actual value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isTrue
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isTrue : function (actual /*:Boolean*/, message /*:String*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (true !== actual) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Value should be true."), true, actual);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Special Value Assertion Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is not a number.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isNaN
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isNaN : function (actual /*:Object*/, message /*:String*/) /*:Void*/{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!isNaN(actual)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Value should be NaN."), NaN, actual);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is not the special NaN value.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isNotNaN
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isNotNaN : function (actual /*:Object*/, message /*:String*/) /*:Void*/{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (isNaN(actual)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.UnexpectedValue(Y.Assert._formatMessage(message, "Values should not be NaN."), NaN);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is not null. This uses the triple equals sign
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * so no type cohersion may occur.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The actual value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isNotNull
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isNotNull : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (Y.Lang.isNull(actual)) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.UnexpectedValue(Y.Assert._formatMessage(message, "Values should not be null."), null);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is not undefined. This uses the triple equals sign
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * so no type cohersion may occur.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The actual value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * @method isNotUndefined
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isNotUndefined : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (Y.Lang.isUndefined(actual)) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.UnexpectedValue(Y.Assert._formatMessage(message, "Value should not be undefined."), undefined);
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync }
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync },
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync /**
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync * Asserts that a value is null. This uses the triple equals sign
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync * so no type cohersion may occur.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The actual value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isNull
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync */
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync isNull : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
02e851310fa6b70ff20500172a9758a50731a451vboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!Y.Lang.isNull(actual)) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Value should be null."), null, actual);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync },
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync /**
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync * Asserts that a value is undefined. This uses the triple equals sign
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync * so no type cohersion may occur.
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync * @param {Object} actual The actual value to test.
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync * @param {String} message (Optional) The message to display if the assertion fails.
a144bb4a097a1818739e00ba31bea88ce63f5345vboxsync * @method isUndefined
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync * @static
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync */
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync isUndefined : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync Y.Assert._increment();
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync if (!Y.Lang.isUndefined(actual)) {
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Value should be undefined."), undefined, actual);
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync }
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //--------------------------------------------------------------------------
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync // Instance Assertion Methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //--------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync /**
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync * Asserts that a value is an array.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isArray
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isArray : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync Y.Assert._increment();
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync if (!Y.Lang.isArray(actual)){
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync throw new Y.Assert.UnexpectedValue(Y.Assert._formatMessage(message, "Value should be an array."), actual);
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync }
daf1b2aee694fc8aca9e056e825b3359170ecf37vboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is a Boolean.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The value to test.
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync * @method isBoolean
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isBoolean : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!Y.Lang.isBoolean(actual)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.UnexpectedValue(Y.Assert._formatMessage(message, "Value should be a Boolean."), actual);
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is a function.
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync * @param {Object} actual The value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isFunction
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync * @static
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isFunction : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync Y.Assert._increment();
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync if (!Y.Lang.isFunction(actual)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.UnexpectedValue(Y.Assert._formatMessage(message, "Value should be a function."), actual);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is an instance of a particular object. This may return
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * incorrect results when comparing objects from one frame to constructors in
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync * another frame. For best results, don't use in a cross-frame manner.
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync * @param {Function} expected The function that the object should be an instance of.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The object to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isInstanceOf
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isInstanceOf : function (expected /*:Function*/, actual /*:Object*/, message /*:String*/) /*:Void*/ {
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync Y.Assert._increment();
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync if (!(actual instanceof expected)){
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Value isn't an instance of expected type."), expected, actual);
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync }
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync },
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync /**
564cc620447c495b6ff9cbb9274e225692fe38dfvboxsync * Asserts that a value is a number.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isNumber
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isNumber : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!Y.Lang.isNumber(actual)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.UnexpectedValue(Y.Assert._formatMessage(message, "Value should be a number."), actual);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is an object.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isObject
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isObject : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!Y.Lang.isObject(actual)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.UnexpectedValue(Y.Assert._formatMessage(message, "Value should be an object."), actual);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is a string.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isString
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isString : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!Y.Lang.isString(actual)){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.UnexpectedValue(Y.Assert._formatMessage(message, "Value should be a string."), actual);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a value is of a particular type.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} expectedType The expected type of the variable.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actualValue The actual value to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message (Optional) The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method isTypeOf
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync isTypeOf : function (expectedType /*:String*/, actualValue /*:Object*/, message /*:String*/) /*:Void*/{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (typeof actualValue != expectedType){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Value should be of type " + expectedType + "."), expected, typeof actualValue);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Asserts that a given condition is true. If not, then a Y.Assert.Error object is thrown
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * and the test fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method Y.assert
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Boolean} condition The condition to test.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message The message to display if the assertion fails.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @static
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.assert = function(condition, message){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert._increment();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!condition){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync throw new Y.Assert.Error(Y.Assert._formatMessage(message, "Assertion failed."));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-----------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // Assertion errors
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //-----------------------------------------------------------------------------
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Error is thrown whenever an assertion fails. It provides methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * to more easily get at error information and also provides a base class
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * from which more specific assertion errors can be derived.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message The message to display when the error occurs.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @namespace Assert
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @class Error
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @constructor
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert.Error = function (message /*:String*/){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //call superclass
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync arguments.callee.superclass.constructor.call(this, message);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /*
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Error message. Must be duplicated to ensure browser receives it.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type String
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property message
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.message /*:String*/ = message;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * The name of the error that occurred.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @type String
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @property name
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync this.name /*:String*/ = "Assert Error";
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //inherit methods
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.extend(Y.Assert.Error, Error, {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Returns a fully formatted error for an assertion failure. This should
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * be overridden by all subclasses to provide specific information.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method getMessage
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {String} A string describing the error.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync getMessage : function () /*:String*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return this.message;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Returns a string representation of the error.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method toString
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {String} A string representation of the error.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync toString : function () /*:String*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return this.name + ": " + this.getMessage();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Returns a primitive value version of the error. Same as toString().
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @method valueOf
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return {String} A primitive value version of the error.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync valueOf : function () /*:String*/ {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return this.toString();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync });
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * ComparisonFailure is subclass of Error that is thrown whenever
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * a comparison between two values fails. It provides mechanisms to retrieve
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * both the expected and actual value.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {String} message The message to display when the error occurs.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} expected The expected value.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param {Object} actual The actual value that caused the assertion to fail.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @namespace Assert
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @extends Assert.Error
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @class ComparisonFailure
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @constructor
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Y.Assert.ComparisonFailure = function (message /*:String*/, expected /*:Object*/, actual /*:Object*/){
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync //call superclass
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync arguments.callee.superclass.constructor.call(this, message);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
/**
* The expected value.
* @type Object
* @property expected
*/
this.expected /*:Object*/ = expected;
/**
* The actual value.
* @type Object
* @property actual
*/
this.actual /*:Object*/ = actual;
/**
* The name of the error that occurred.
* @type String
* @property name
*/
this.name /*:String*/ = "ComparisonFailure";
};
//inherit methods
Y.extend(Y.Assert.ComparisonFailure, Y.Assert.Error, {
/**
* Returns a fully formatted error for an assertion failure. This message
* provides information about the expected and actual values.
* @method toString
* @return {String} A string describing the error.
*/
getMessage : function () /*:String*/ {
return this.message + "\nExpected: " + this.expected + " (" + (typeof this.expected) + ")" +
"\nActual:" + this.actual + " (" + (typeof this.actual) + ")";
}
});
/**
* UnexpectedValue is subclass of Error that is thrown whenever
* a value was unexpected in its scope. This typically means that a test
* was performed to determine that a value was *not* equal to a certain
* value.
*
* @param {String} message The message to display when the error occurs.
* @param {Object} unexpected The unexpected value.
* @namespace Assert
* @extends Assert.Error
* @class UnexpectedValue
* @constructor
*/
Y.Assert.UnexpectedValue = function (message /*:String*/, unexpected /*:Object*/){
//call superclass
arguments.callee.superclass.constructor.call(this, message);
/**
* The unexpected value.
* @type Object
* @property unexpected
*/
this.unexpected /*:Object*/ = unexpected;
/**
* The name of the error that occurred.
* @type String
* @property name
*/
this.name /*:String*/ = "UnexpectedValue";
};
//inherit methods
Y.extend(Y.Assert.UnexpectedValue, Y.Assert.Error, {
/**
* Returns a fully formatted error for an assertion failure. The message
* contains information about the unexpected value that was encountered.
* @method getMessage
* @return {String} A string describing the error.
*/
getMessage : function () /*:String*/ {
return this.message + "\nUnexpected: " + this.unexpected + " (" + (typeof this.unexpected) + ") ";
}
});
/**
* ShouldFail is subclass of Error that is thrown whenever
* a test was expected to fail but did not.
*
* @param {String} message The message to display when the error occurs.
* @namespace Assert
* @extends Assert.Error
* @class ShouldFail
* @constructor
*/
Y.Assert.ShouldFail = function (message /*:String*/){
//call superclass
arguments.callee.superclass.constructor.call(this, message || "This test should fail but didn't.");
/**
* The name of the error that occurred.
* @type String
* @property name
*/
this.name /*:String*/ = "ShouldFail";
};
//inherit methods
Y.extend(Y.Assert.ShouldFail, Y.Assert.Error);
/**
* ShouldError is subclass of Error that is thrown whenever
* a test is expected to throw an error but doesn't.
*
* @param {String} message The message to display when the error occurs.
* @namespace Assert
* @extends Assert.Error
* @class ShouldError
* @constructor
*/
Y.Assert.ShouldError = function (message /*:String*/){
//call superclass
arguments.callee.superclass.constructor.call(this, message || "This test should have thrown an error but didn't.");
/**
* The name of the error that occurred.
* @type String
* @property name
*/
this.name /*:String*/ = "ShouldError";
};
//inherit methods
Y.extend(Y.Assert.ShouldError, Y.Assert.Error);
/**
* UnexpectedError is subclass of Error that is thrown whenever
* an error occurs within the course of a test and the test was not expected
* to throw an error.
*
* @param {Error} cause The unexpected error that caused this error to be
* thrown.
* @namespace Assert
* @extends Assert.Error
* @class UnexpectedError
* @constructor
*/
Y.Assert.UnexpectedError = function (cause /*:Object*/){
//call superclass
arguments.callee.superclass.constructor.call(this, "Unexpected error: " + cause.message);
/**
* The unexpected error that occurred.
* @type Error
* @property cause
*/
this.cause /*:Error*/ = cause;
/**
* The name of the error that occurred.
* @type String
* @property name
*/
this.name /*:String*/ = "UnexpectedError";
/**
* Stack information for the error (if provided).
* @type String
* @property stack
*/
this.stack /*:String*/ = cause.stack;
};
//inherit methods
Y.extend(Y.Assert.UnexpectedError, Y.Assert.Error);
/**
* The ArrayAssert object provides functions to test JavaScript array objects
* for a variety of cases.
*
* @class ArrayAssert
* @static
*/
Y.ArrayAssert = {
/**
* Asserts that a value is present in an array. This uses the triple equals
* sign so no type cohersion may occur.
* @param {Object} needle The value that is expected in the array.
* @param {Array} haystack An array of values.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method contains
* @static
*/
contains : function (needle /*:Object*/, haystack /*:Array*/,
message /*:String*/) /*:Void*/ {
Y.Assert._increment();
if (Y.Array.indexOf(haystack, needle) == -1){
Y.Assert.fail(Y.Assert._formatMessage(message, "Value " + needle + " (" + (typeof needle) + ") not found in array [" + haystack + "]."));
}
},
/**
* Asserts that a set of values are present in an array. This uses the triple equals
* sign so no type cohersion may occur. For this assertion to pass, all values must
* be found.
* @param {Object[]} needles An array of values that are expected in the array.
* @param {Array} haystack An array of values to check.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method containsItems
* @static
*/
containsItems : function (needles /*:Object[]*/, haystack /*:Array*/,
message /*:String*/) /*:Void*/ {
Y.Assert._increment();
//begin checking values
for (var i=0; i < needles.length; i++){
if (Y.Array.indexOf(haystack, needles[i]) == -1){
Y.Assert.fail(Y.Assert._formatMessage(message, "Value " + needles[i] + " (" + (typeof needles[i]) + ") not found in array [" + haystack + "]."));
}
}
},
/**
* Asserts that a value matching some condition is present in an array. This uses
* a function to determine a match.
* @param {Function} matcher A function that returns true if the items matches or false if not.
* @param {Array} haystack An array of values.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method containsMatch
* @static
*/
containsMatch : function (matcher /*:Function*/, haystack /*:Array*/,
message /*:String*/) /*:Void*/ {
Y.Assert._increment();
//check for valid matcher
if (typeof matcher != "function"){
throw new TypeError("ArrayAssert.containsMatch(): First argument must be a function.");
}
if (!Y.Array.some(matcher)){
Y.Assert.fail(Y.Assert._formatMessage(message, "No match found in array [" + haystack + "]."));
}
},
/**
* Asserts that a value is not present in an array. This uses the triple equals
* Asserts that a value is not present in an array. This uses the triple equals
* sign so no type cohersion may occur.
* @param {Object} needle The value that is expected in the array.
* @param {Array} haystack An array of values.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method doesNotContain
* @static
*/
doesNotContain : function (needle /*:Object*/, haystack /*:Array*/,
message /*:String*/) /*:Void*/ {
Y.Assert._increment();
if (Y.Array.indexOf(haystack, needle) > -1){
Y.Assert.fail(Y.Assert._formatMessage(message, "Value found in array [" + haystack + "]."));
}
},
/**
* Asserts that a set of values are not present in an array. This uses the triple equals
* sign so no type cohersion may occur. For this assertion to pass, all values must
* not be found.
* @param {Object[]} needles An array of values that are not expected in the array.
* @param {Array} haystack An array of values to check.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method doesNotContainItems
* @static
*/
doesNotContainItems : function (needles /*:Object[]*/, haystack /*:Array*/,
message /*:String*/) /*:Void*/ {
Y.Assert._increment();
for (var i=0; i < needles.length; i++){
if (Y.Array.indexOf(haystack, needles[i]) > -1){
Y.Assert.fail(Y.Assert._formatMessage(message, "Value found in array [" + haystack + "]."));
}
}
},
/**
* Asserts that no values matching a condition are present in an array. This uses
* a function to determine a match.
* @param {Function} matcher A function that returns true if the items matches or false if not.
* @param {Array} haystack An array of values.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method doesNotContainMatch
* @static
*/
doesNotContainMatch : function (matcher /*:Function*/, haystack /*:Array*/,
message /*:String*/) /*:Void*/ {
Y.Assert._increment();
//check for valid matcher
if (typeof matcher != "function"){
throw new TypeError("ArrayAssert.doesNotContainMatch(): First argument must be a function.");
}
if (Y.Array.some(matcher)){
Y.Assert.fail(Y.Assert._formatMessage(message, "Value found in array [" + haystack + "]."));
}
},
/**
* Asserts that the given value is contained in an array at the specified index.
* This uses the triple equals sign so no type cohersion will occur.
* @param {Object} needle The value to look for.
* @param {Array} haystack The array to search in.
* @param {int} index The index at which the value should exist.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method indexOf
* @static
*/
indexOf : function (needle /*:Object*/, haystack /*:Array*/, index /*:int*/, message /*:String*/) /*:Void*/ {
Y.Assert._increment();
//try to find the value in the array
for (var i=0; i < haystack.length; i++){
if (haystack[i] === needle){
if (index != i){
Y.Assert.fail(Y.Assert._formatMessage(message, "Value exists at index " + i + " but should be at index " + index + "."));
}
return;
}
}
//if it makes it here, it wasn't found at all
Y.Assert.fail(Y.Assert._formatMessage(message, "Value doesn't exist in array [" + haystack + "]."));
},
/**
* Asserts that the values in an array are equal, and in the same position,
* as values in another array. This uses the double equals sign
* so type cohersion may occur. Note that the array objects themselves
* need not be the same for this test to pass.
* @param {Array} expected An array of the expected values.
* @param {Array} actual Any array of the actual values.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method itemsAreEqual
* @static
*/
itemsAreEqual : function (expected /*:Array*/, actual /*:Array*/,
message /*:String*/) /*:Void*/ {
Y.Assert._increment();
//first check array length
if (expected.length != actual.length){
Y.Assert.fail(Y.Assert._formatMessage(message, "Array should have a length of " + expected.length + " but has a length of " + actual.length));
}
//begin checking values
for (var i=0; i < expected.length; i++){
if (expected[i] != actual[i]){
throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Values in position " + i + " are not equal."), expected[i], actual[i]);
}
}
},
/**
* Asserts that the values in an array are equivalent, and in the same position,
* as values in another array. This uses a function to determine if the values
* are equivalent. Note that the array objects themselves
* need not be the same for this test to pass.
* @param {Array} expected An array of the expected values.
* @param {Array} actual Any array of the actual values.
* @param {Function} comparator A function that returns true if the values are equivalent
* or false if not.
* @param {String} message (Optional) The message to display if the assertion fails.
* @return {Void}
* @method itemsAreEquivalent
* @static
*/
itemsAreEquivalent : function (expected /*:Array*/, actual /*:Array*/,
comparator /*:Function*/, message /*:String*/) /*:Void*/ {
Y.Assert._increment();
//make sure the comparator is valid
if (typeof comparator != "function"){
throw new TypeError("ArrayAssert.itemsAreEquivalent(): Third argument must be a function.");
}
//first check array length
if (expected.length != actual.length){
Y.Assert.fail(Y.Assert._formatMessage(message, "Array should have a length of " + expected.length + " but has a length of " + actual.length));
}
//begin checking values
for (var i=0; i < expected.length; i++){
if (!comparator(expected[i], actual[i])){
throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Values in position " + i + " are not equivalent."), expected[i], actual[i]);
}
}
},
/**
* Asserts that an array is empty.
* @param {Array} actual The array to test.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method isEmpty
* @static
*/
isEmpty : function (actual /*:Array*/, message /*:String*/) /*:Void*/ {
Y.Assert._increment();
if (actual.length > 0){
Y.Assert.fail(Y.Assert._formatMessage(message, "Array should be empty."));
}
},
/**
* Asserts that an array is not empty.
* @param {Array} actual The array to test.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method isNotEmpty
* @static
*/
isNotEmpty : function (actual /*:Array*/, message /*:String*/) /*:Void*/ {
Y.Assert._increment();
if (actual.length === 0){
Y.Assert.fail(Y.Assert._formatMessage(message, "Array should not be empty."));
}
},
/**
* Asserts that the values in an array are the same, and in the same position,
* as values in another array. This uses the triple equals sign
* so no type cohersion will occur. Note that the array objects themselves
* need not be the same for this test to pass.
* @param {Array} expected An array of the expected values.
* @param {Array} actual Any array of the actual values.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method itemsAreSame
* @static
*/
itemsAreSame : function (expected /*:Array*/, actual /*:Array*/,
message /*:String*/) /*:Void*/ {
Y.Assert._increment();
//first check array length
if (expected.length != actual.length){
Y.Assert.fail(Y.Assert._formatMessage(message, "Array should have a length of " + expected.length + " but has a length of " + actual.length));
}
//begin checking values
for (var i=0; i < expected.length; i++){
if (expected[i] !== actual[i]){
throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Values in position " + i + " are not the same."), expected[i], actual[i]);
}
}
},
/**
* Asserts that the given value is contained in an array at the specified index,
* starting from the back of the array.
* This uses the triple equals sign so no type cohersion will occur.
* @param {Object} needle The value to look for.
* @param {Array} haystack The array to search in.
* @param {int} index The index at which the value should exist.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method lastIndexOf
* @static
*/
lastIndexOf : function (needle /*:Object*/, haystack /*:Array*/, index /*:int*/, message /*:String*/) /*:Void*/ {
//try to find the value in the array
for (var i=haystack.length; i >= 0; i--){
if (haystack[i] === needle){
if (index != i){
Y.Assert.fail(Y.Assert._formatMessage(message, "Value exists at index " + i + " but should be at index " + index + "."));
}
return;
}
}
//if it makes it here, it wasn't found at all
Y.Assert.fail(Y.Assert._formatMessage(message, "Value doesn't exist in array."));
}
};
/**
* The ObjectAssert object provides functions to test JavaScript objects
* for a variety of cases.
*
* @class ObjectAssert
* @static
*/
Y.ObjectAssert = {
areEqual: function(expected /*:Object*/, actual /*:Object*/, message /*:String*/) /*:Void*/ {
Y.Assert._increment();
Y.Object.each(expected, function(value, name){
if (expected[name] != actual[name]){
throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, "Values should be equal for property " + name), expected[name], actual[name]);
}
});
},
/**
* Asserts that an object has a property with the given name.
* @param {String} propertyName The name of the property to test.
* @param {Object} object The object to search.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method has
* @static
*/
has : function (propertyName /*:String*/, object /*:Object*/, message /*:String*/) /*:Void*/ {
Y.Assert._increment();
if (!(propertyName in object)){
Y.Assert.fail(Y.Assert._formatMessage(message, "Property '" + propertyName + "' not found on object."));
}
},
/**
* Asserts that an object has all properties of a reference object.
* @param {Object} refObject The object whose properties should be on the object to test.
* @param {Object} object The object to search.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method hasAll
* @static
*/
hasAll : function (refObject /*:Object*/, object /*:Object*/, message /*:String*/) /*:Void*/ {
Y.Assert._increment();
Y.Object.each(refObject, function(value, name){
if (!(name in object)){
Y.Assert.fail(Y.Assert._formatMessage(message, "Property '" + name + "' not found on object."));
}
});
},
/**
* Asserts that a property with the given name exists on an object instance (not on its prototype).
* @param {String} propertyName The name of the property to test.
* @param {Object} object The object to search.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method owns
* @static
*/
owns : function (propertyName /*:String*/, object /*:Object*/, message /*:String*/) /*:Void*/ {
Y.Assert._increment();
if (!object.hasOwnProperty(propertyName)){
Y.Assert.fail(Y.Assert._formatMessage(message, "Property '" + propertyName + "' not found on object instance."));
}
},
/**
* Asserts that all properties on a given object also exist on an object instance (not on its prototype).
* @param {Object} refObject The object whose properties should be owned by the object to test.
* @param {Object} object The object to search.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method ownsAll
* @static
*/
ownsAll : function (refObject /*:Object*/, object /*:Object*/, message /*:String*/) /*:Void*/ {
Y.Assert._increment();
Y.Object.each(refObject, function(value, name){
if (!object.hasOwnProperty(name)){
Y.Assert.fail(Y.Assert._formatMessage(message, "Property '" + name + "' not found on object instance."));
}
});
}
};
/**
* The DateAssert object provides functions to test JavaScript Date objects
* for a variety of cases.
*
* @class DateAssert
* @static
*/
Y.DateAssert = {
/**
* Asserts that a date's month, day, and year are equal to another date's.
* @param {Date} expected The expected date.
* @param {Date} actual The actual date to test.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method datesAreEqual
* @static
*/
datesAreEqual : function (expected /*:Date*/, actual /*:Date*/, message /*:String*/){
Y.Assert._increment();
if (expected instanceof Date && actual instanceof Date){
var msg = "";
//check years first
if (expected.getFullYear() != actual.getFullYear()){
msg = "Years should be equal.";
}
//now check months
if (expected.getMonth() != actual.getMonth()){
msg = "Months should be equal.";
}
//last, check the day of the month
if (expected.getDate() != actual.getDate()){
msg = "Days of month should be equal.";
}
if (msg.length){
throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, msg), expected, actual);
}
} else {
throw new TypeError("Y.Assert.datesAreEqual(): Expected and actual values must be Date objects.");
}
},
/**
* Asserts that a date's hour, minutes, and seconds are equal to another date's.
* @param {Date} expected The expected date.
* @param {Date} actual The actual date to test.
* @param {String} message (Optional) The message to display if the assertion fails.
* @method timesAreEqual
* @static
*/
timesAreEqual : function (expected /*:Date*/, actual /*:Date*/, message /*:String*/){
Y.Assert._increment();
if (expected instanceof Date && actual instanceof Date){
var msg = "";
//check hours first
if (expected.getHours() != actual.getHours()){
msg = "Hours should be equal.";
}
//now check minutes
if (expected.getMinutes() != actual.getMinutes()){
msg = "Minutes should be equal.";
}
//last, check the seconds
if (expected.getSeconds() != actual.getSeconds()){
msg = "Seconds should be equal.";
}
if (msg.length){
throw new Y.Assert.ComparisonFailure(Y.Assert._formatMessage(message, msg), expected, actual);
}
} else {
throw new TypeError("DateY.AsserttimesAreEqual(): Expected and actual values must be Date objects.");
}
}
};
Y.namespace("Test.Format");
/**
* Returns test results formatted as a JSON string. Requires JSON utility.
* @param {Object} result The results object created by TestRunner.
* @return {String} A JSON-formatted string of results.
* @namespace Test.Format
* @method JSON
* @static
*/
Y.Test.Format.JSON = function(results /*:Object*/) /*:String*/ {
return Y.JSON.stringify(results);
};
/**
* Returns test results formatted as an XML string.
* @param {Object} result The results object created by TestRunner.
* @return {String} An XML-formatted string of results.
* @namespace Test.Format
* @method XML
* @static
*/
Y.Test.Format.XML = function(results /*:Object*/) /*:String*/ {
var l = Y.Lang;
var xml /*:String*/ = "<" + results.type + " name=\"" + results.name.replace(/"/g, "&quot;").replace(/'/g, "&apos;") + "\"";
if (results.type == "test"){
xml += " result=\"" + results.result + "\" message=\"" + results.message + "\">";
} else {
xml += " passed=\"" + results.passed + "\" failed=\"" + results.failed + "\" ignored=\"" + results.ignored + "\" total=\"" + results.total + "\">";
Y.Object.each(results, function(value, prop){
if (l.isObject(value) && !l.isArray(value)){
xml += arguments.callee(value);
}
});
}
xml += "</" + results.type + ">";
return xml;
};
Y.namespace("Test");
/**
* An object capable of sending test results to a server.
* @param {String} url The URL to submit the results to.
* @param {Function} format (Optiona) A function that outputs the results in a specific format.
* Default is Y.Test.Format.XML.
* @constructor
* @namespace Test
* @class Reporter
*/
Y.Test.Reporter = function(url /*:String*/, format /*:Function*/) {
/**
* The URL to submit the data to.
* @type String
* @property url
*/
this.url /*:String*/ = url;
/**
* The formatting function to call when submitting the data.
* @type Function
* @property format
*/
this.format /*:Function*/ = format || Y.Test.Format.XML;
/**
* Extra fields to submit with the request.
* @type Object
* @property _fields
* @private
*/
this._fields /*:Object*/ = new Object();
/**
* The form element used to submit the results.
* @type HTMLFormElement
* @property _form
* @private
*/
this._form /*:HTMLElement*/ = null;
/**
* Iframe used as a target for form submission.
* @type HTMLIFrameElement
* @property _iframe
* @private
*/
this._iframe /*:HTMLElement*/ = null;
};
Y.Test.Reporter.prototype = {
//restore missing constructor
constructor: Y.Test.Reporter,
/**
* Adds a field to the form that submits the results.
* @param {String} name The name of the field.
* @param {Variant} value The value of the field.
* @return {Void}
* @method addField
*/
addField : function (name /*:String*/, value /*:Variant*/) /*:Void*/{
this._fields[name] = value;
},
/**
* Removes all previous defined fields.
* @return {Void}
* @method addField
*/
clearFields : function() /*:Void*/{
this._fields = new Object();
},
/**
* Cleans up the memory associated with the TestReporter, removing DOM elements
* that were created.
* @return {Void}
* @method destroy
*/
destroy : function() /*:Void*/ {
if (this._form){
this._form.parentNode.removeChild(this._form);
this._form = null;
}
if (this._iframe){
this._iframe.parentNode.removeChild(this._iframe);
this._iframe = null;
}
this._fields = null;
},
/**
* Sends the report to the server.
* @param {Object} results The results object created by TestRunner.
* @return {Void}
* @method report
*/
report : function(results /*:Object*/) /*:Void*/{
//if the form hasn't been created yet, create it
if (!this._form){
this._form = document.createElement("form");
this._form.method = "post";
this._form.style.visibility = "hidden";
this._form.style.position = "absolute";
this._form.style.top = 0;
document.body.appendChild(this._form);
//IE won't let you assign a name using the DOM, must do it the hacky way
if (Y.UA.ie){
this._iframe = document.createElement("<iframe name=\"yuiTestTarget\" />");
} else {
this._iframe = document.createElement("iframe");
this._iframe.name = "yuiTestTarget";
}
this._iframe.src = "javascript:false";
this._iframe.style.visibility = "hidden";
this._iframe.style.position = "absolute";
this._iframe.style.top = 0;
document.body.appendChild(this._iframe);
this._form.target = "yuiTestTarget";
}
//set the form's action
this._form.action = this.url;
//remove any existing fields
while(this._form.hasChildNodes()){
this._form.removeChild(this._form.lastChild);
}
//create default fields
this._fields.results = this.format(results);
this._fields.useragent = navigator.userAgent;
this._fields.timestamp = (new Date()).toLocaleString();
//add fields to the form
Y.Object.each(this._fields, function(value, prop){
if (typeof value != "function"){
var input = document.createElement("input");
input.type = "hidden";
input.name = prop;
input.value = value;
this._form.appendChild(input);
}
});
//remove default fields
delete this._fields.results;
delete this._fields.useragent;
delete this._fields.timestamp;
if (arguments[1] !== false){
this._form.submit();
}
}
};
/**
* Creates a new mock object.
* @class Mock
* @constructor
* @param {Object} template (Optional) An object whose methods
* should be stubbed out on the mock object.
*/
Y.Mock = function(template){
//use blank object is nothing is passed in
template = template || {};
var mock = null;
//try to create mock that keeps prototype chain intact
try {
mock = Y.Object(template);
} catch (ex) {
mock = {};
Y.log("Couldn't create mock with prototype.", "warn", "Mock");
}
//create new versions of the methods so that they don't actually do anything
Y.Object.each(template, function(name){
if (Y.Lang.isFunction(template[name])){
mock[name] = function(){
Y.Assert.fail("Method " + name + "() was called but was not expected to be.");
};
}
});
//return it
return mock;
};
/**
* Assigns an expectation to a mock object. This is used to create
* methods and properties on the mock object that are monitored for
* calls and changes, respectively.
* @param {Object} mock The object to add the expectation to.
* @param {Object} expectation An object defining the expectation. For
* a method, the keys "method" and "args" are required with
* an optional "returns" key available. For properties, the keys
* "property" and "value" are required.
* @return {void}
* @method expect
* @static
*/
Y.Mock.expect = function(mock /*:Object*/, expectation /*:Object*/){
//make sure there's a place to store the expectations
if (!mock.__expectations) {
mock.__expectations = {};
}
//method expectation
if (expectation.method){
var name = expectation.method,
args = expectation.args || expectation.arguments || [],
result = expectation.returns,
callCount = Y.Lang.isNumber(expectation.callCount) ? expectation.callCount : 1,
error = expectation.error,
run = expectation.run || function(){};
//save expectations
mock.__expectations[name] = expectation;
expectation.callCount = callCount;
expectation.actualCallCount = 0;
//process arguments
Y.Array.each(args, function(arg, i, array){
if (!(array[i] instanceof Y.Mock.Value)){
array[i] = Y.Mock.Value(Y.Assert.areSame, [arg], "Argument " + i + " of " + name + "() is incorrect.");
}
});
//if the method is expected to be called
if (callCount > 0){
mock[name] = function(){
expectation.actualCallCount++;
Y.Assert.areEqual(args.length, arguments.length, "Method " + name + "() passed incorrect number of arguments.");
for (var i=0, len=args.length; i < len; i++){
if (args[i]){
args[i].verify(arguments[i]);
} else {
Y.Assert.fail("Argument " + i + " (" + arguments[i] + ") was not expected to be used.");
}
}
run.apply(this, arguments);
if (error){
throw error;
}
return result;
};
} else {
//method should fail if called when not expected
mock[name] = function(){
Y.Assert.fail("Method " + name + "() should not have been called.");
};
}
} else if (expectation.property){
//save expectations
mock.__expectations[name] = expectation;
}
};
/**
* Verifies that all expectations of a mock object have been met and
* throws an assertion error if not.
* @param {Object} mock The object to verify..
* @return {void}
* @method verify
* @static
*/
Y.Mock.verify = function(mock /*:Object*/){
Y.Object.each(mock.__expectations, function(expectation){
if (expectation.method) {
Y.Assert.areEqual(expectation.callCount, expectation.actualCallCount, "Method " + expectation.method + "() wasn't called the expected number of times.");
} else if (expectation.property){
Y.Assert.areEqual(expectation.value, mock[expectation.property], "Property " + expectation.property + " wasn't set to the correct value.");
}
});
};
Y.Mock.Value = function(method, args, message){
if (this instanceof Y.Mock.Value){
this.verify = function(value){
args = [].concat(args || []);
args.push(value);
args.push(message);
method.apply(null, args);
};
} else {
return new Y.Mock.Value(method, args, message);
}
};
Y.Mock.Value.Any = Y.Mock.Value(function(){});
Y.Mock.Value.Boolean = Y.Mock.Value(Y.Assert.isBoolean);
Y.Mock.Value.Number = Y.Mock.Value(Y.Assert.isNumber);
Y.Mock.Value.String = Y.Mock.Value(Y.Assert.isString);
Y.Mock.Value.Object = Y.Mock.Value(Y.Assert.isObject);
Y.Mock.Value.Function = Y.Mock.Value(Y.Assert.isFunction);
}, '@VERSION@' ,{requires:['substitute','event-custom','array','oop','event','event-simulate']});