src/cm/media/js/lib/yui/yui3.0.0/examples/test/test-async-test_clean.html
author raph
Mon, 23 Nov 2009 15:14:29 +0100
changeset 0 40c8f766c9b8
permissions -rw-r--r--
import from internal svn r 4007


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Asynchronous Testing</title>

<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
	margin:0;
	padding:0;
}
</style>

<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yui/yui-min.js"></script>


<!--begin custom header content for this example-->
<style type="text/css">
#testLogger {
    margin-bottom: 1em;
}

#testLogger .yui-console .yui-console-title {
    border: 0 none;
    color: #000;
    font-size: 13px;
    font-weight: bold;
    margin: 0;
    text-transform: none;
}
#testLogger .yui-console .yui-console-entry-meta {
    margin: 0;
}

.yui-skin-sam .yui-console-entry-pass .yui-console-entry-cat {
    background: #070;
    color: #fff;
}
</style>

<!--end custom header content for this example-->

</head>

<body class=" yui-skin-sam">

<h1>Asynchronous Testing</h1>

<div class="exampleIntro">
	<p>This example shows how to create an asynchronous test with the YUI Test framework for testing browser-based JavaScript code. 
  A <code>Y.Test.Case</code> object is created with a test that waits for a
  few seconds before continuing. The <code>Y.Test.Runner</code>
  is then used to run the tests once the page has loaded.</p>			
</div>

<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

<div id="testLogger"></div>
<script type="text/javascript">
YUI({base:"../../build/", timeout: 10000}).use("node", "console", "test",function (Y) {

    Y.namespace("example.test");
    
    Y.example.test.AsyncTestCase = new Y.Test.Case({
    
        //name of the test case - if not provided, one is auto-generated
        name : "Asynchronous Tests",
        
        //---------------------------------------------------------------------
        // setUp and tearDown methods - optional
        //---------------------------------------------------------------------
        
        /*
         * Sets up data that is needed by each test.
         */
        setUp : function () {
            this.data = {
                name: "test",
                year: 2007,
                beta: true
            };
        },
        
        /*
         * Cleans up everything that was created by setUp().
         */
        tearDown : function () {
            delete this.data;
        },
                
        //---------------------------------------------------------------------
        // Test methods - names must begin with "test"
        //---------------------------------------------------------------------
        
        testWait : function (){
            var Assert = Y.Assert;
            
            //do some assertions now
            Assert.isTrue(this.data.beta);
            Assert.isNumber(this.data.year);
            
            //wait five seconds and do some more
            this.wait(function(){
            
                Assert.isString(this.data.name);                
            
            }, 5000);
        
        }
                    
    });
     
    //create the console
    var r = new Y.Console({
        newestOnTop : false,
        style: 'block' // to anchor in the example content
    });
    
    r.render('#testLogger');

    Y.Test.Runner.add(Y.example.test.AsyncTestCase);

    //run the tests
    Y.Test.Runner.run();
});

</script>

<!--END SOURCE CODE FOR EXAMPLE =============================== -->

</body>
</html>