-
-
Save alfredwesterveld/2713ee166ca6d10365ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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>Simple Testing Example</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="http://yui.yahooapis.com/3.3.0/build/cssfonts/fonts-min.css" /> | |
<script type="text/javascript" src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script> | |
<!--begin custom header content for this example--> | |
<style type="text/css"> | |
#testLogger { | |
margin-bottom: 1em; | |
} | |
#testLogger .yui3-console .yui3-console-title { | |
border: 0 none; | |
color: #000; | |
font-size: 13px; | |
font-weight: bold; | |
margin: 0; | |
text-transform: none; | |
} | |
#testLogger .yui3-console .yui3-console-entry-meta { | |
margin: 0; | |
} | |
.yui3-skin-sam .yui3-console-entry-pass .yui3-console-entry-cat { | |
background: #070; | |
color: #fff; | |
} | |
</style> | |
<!--end custom header content for this example--> | |
</head> | |
<body class="yui3-skin-sam yui-skin-sam"> | |
<h1>Simple Testing Example</h1> | |
<div class="exampleIntro"> | |
<p>This example shows basic usage of the YUI Test framework for testing browser-based JavaScript code. | |
Two different <a href="/yui/test/#testcase"><code>TestCase</code></a> objects are created and added to a | |
<a href="/yui/test/#testsuite"><code>TestSuite</code></a> object. The <a href="/yui/test/#testrunner"><code>TestRunner</code></a> | |
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({ filter: 'raw' }).use("node", "console", "test",function (Y) { | |
Y.namespace("example.test"); | |
Y.example.test.DataTestCase = new Y.Test.Case({ | |
//name of the test case - if not provided, one is auto-generated | |
name : "Data 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" | |
//--------------------------------------------------------------------- | |
testName : function () { | |
var Assert = Y.Assert; | |
Assert.isObject(this.data); | |
Assert.isString(this.data.name); | |
Assert.areEqual("test", this.data.name); | |
}, | |
testYear : function () { | |
var Assert = Y.Assert; | |
Assert.isObject(this.data); | |
Assert.isNumber(this.data.year); | |
Assert.areEqual(2007, this.data.year); | |
}, | |
testBeta : function () { | |
var Assert = Y.Assert; | |
Assert.isObject(this.data); | |
Assert.isBoolean(this.data.beta); | |
Assert.isTrue(this.data.beta); | |
} | |
}); | |
Y.example.test.ArrayTestCase = new Y.Test.Case({ | |
//name of the test case - if not provided, one is auto-generated | |
name : "Array Tests", | |
//--------------------------------------------------------------------- | |
// setUp and tearDown methods - optional | |
//--------------------------------------------------------------------- | |
/* | |
* Sets up data that is needed by each test. | |
*/ | |
setUp : function () { | |
this.data = [0,1,2,3,4] | |
}, | |
/* | |
* Cleans up everything that was created by setUp(). | |
*/ | |
tearDown : function () { | |
delete this.data; | |
}, | |
//--------------------------------------------------------------------- | |
// Test methods - names must begin with "test" | |
//--------------------------------------------------------------------- | |
testPop : function () { | |
var Assert = Y.Assert; | |
var value = this.data.pop(); | |
Assert.areEqual(4, this.data.length); | |
Assert.areEqual(4, value); | |
}, | |
testPush : function () { | |
var Assert = Y.Assert; | |
this.data.push(5); | |
Assert.areEqual(6, this.data.length); | |
Assert.areEqual(5, this.data[5]); | |
}, | |
testSplice : function () { | |
var Assert = Y.Assert; | |
this.data.splice(2, 1, 6, 7); | |
Assert.areEqual(6, this.data.length); | |
Assert.areEqual(6, this.data[2]); | |
Assert.areEqual(7, this.data[3]); | |
} | |
}); | |
Y.example.test.ExampleSuite = new Y.Test.Suite("Example Suite"); | |
Y.example.test.ExampleSuite.add(Y.example.test.DataTestCase); | |
Y.example.test.ExampleSuite.add(Y.example.test.ArrayTestCase); | |
//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.ExampleSuite); | |
//run the tests | |
Y.Test.Runner.run(); | |
}); | |
</script> | |
<!--END SOURCE CODE FOR EXAMPLE =============================== --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment