src/cm/media/js/lib/yui/yui3.0.0/examples/test/test-advanced-test-options_clean.html
author Yves-Marie Haussonne <ymh.work+github@gmail.com>
Fri, 09 May 2014 18:35:26 +0200
changeset 656 a84519031134
parent 0 40c8f766c9b8
permissions -rw-r--r--
add link to "privacy policy" in the header test


<!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>Advanced Test Options</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;
}
.yui-skin-sam .yui-console-entry-fail .yui-console-entry-cat {
    background: #700;
    color: #fff;
}
</style>

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

</head>

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

<h1>Advanced Test Options</h1>

<div class="exampleIntro">
	<p>This example shows how to use advanced test options, which allow you to specify additional information about how a test should be run.
  Each <a href="/yui/test/#testcase"><code>TestCase</code></a> can specify up to three different options for tests,
  including tests that should be ignored, tests that should throw an error, and tests that should fail.</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.AdvancedOptionsTestCase = new Y.Test.Case({
    
        //the name of the test case - if not provided, one is automatically generated
        name: "Advanced Options Tests",
        
        /*
         * Specifies tests that "should" be doing something other than the expected.
         */
        _should: {
        
            /*
             * Tests listed in here should fail, meaning that if they fail, the test
             * has passed. This is used mostly for YuiTest to test itself, but may
             * be helpful in other cases.
             */
            fail: {
            
                //the test named "testFail" should fail
                testFail: true
            
            },
            
            /*
             * Tests listed here should throw an error of some sort. If they throw an
             * error, then they are considered to have passed.
             */
            error: {
            
                /*
                 * You can specify "true" for each test, in which case any error will
                 * cause the test to pass.
                 */
                testGenericError: true,
                
                /*
                 * You can specify an error message, in which case the test passes only
                 * if the error thrown matches the given message.
                 */
                testStringError: "I'm a specific error message.",
                testStringError2: "I'm a specific error message.",
                
                /*
                 * You can also specify an error object, in which case the test passes only
                 * if the error thrown is on the same type and has the same message.
                 */
                testObjectError: new TypeError("Number expected."),            
                testObjectError2: new TypeError("Number expected."),
                testObjectError3: new TypeError("Number expected.")
            
            },
            
            /*
             * Tests listed here should be ignored when the test case is run. For these tests,
             * setUp() and tearDown() are not called.
             */
            ignore : {
            
                testIgnore: true
                
            }    
        },
        
        //-------------------------------------------------------------------------
        // Basic tests - all method names must begin with "test"
        //-------------------------------------------------------------------------
        
        testFail : function() {
        
            //force a failure - but since this test "should" fail, it will pass
            Y.Assert.fail("Something bad happened.");
            
        },
        
        testGenericError : function() {    
            throw new Error("Generic error");        
        },
        
        testStringError : function() {
            
            //throw a specific error message - this will pass because it "should" happen
            throw new Error("I'm a specific error message.");    
        },
        
        testStringError2 : function() {
            
            //throw a specific error message - this will fail because the message isn't expected
            throw new Error("I'm a specific error message, but a wrong one.");    
        },
        
        testObjectError : function() {
            
            //throw a specific error and message - this will pass because it "should" happen
            throw new TypeError("Number expected.");    
        },
        
        testObjectError2 : function() {
            
            //throw a specific error and message - this will fail because the type doesn't match
            throw new Error("Number expected."); 
        },
        
        testObjectError3 : function() {
            
            //throw a specific error and message - this will fail because the message doesn't match
            throw new TypeError("String expected.");    
        },
        
        testIgnore : function () {
            alert("You'll never see this.");
        }
        
    });        
     
     
    //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.AdvancedOptionsTestCase);

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

</script>

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

</body>
</html>