Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Created April 30, 2012 21:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilmoore/2562938 to your computer and use it in GitHub Desktop.
Save wilmoore/2562938 to your computer and use it in GitHub Desktop.
YUI3 Test Skeleton Setup: for testing your YUI3 powered modules
<!doctype html>
<html>
<title>Test Console</title>
<body class="yui3-skin-sam">
<div id="test-console"></div>
<script src="http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js"></script>
<script src="tests.js"></script>
</body>
</html>
// assumes you are testing a module called "yui-powered-module"
YUI({
modules: {
'yui-powered-module': {
fullpath: 'yui-powered-module.js' },
'yui-powered-module-tests': {
fullpath: 'yui-powered-module-tests.js',
requires: ['yui-powered-module'] }
}
}).use('test-console', 'yui-powered-module-tests', function (Y) {
//create the console
(new Y.Test.Console({
verbose : true,
newestOnTop : false,
filters: {
pass: false,
fail: true
}
})).render('#test-console');
//run the tests
Y.Test.Runner.run();
});
/**
* Tests for YuiPoweredModule (yui-powered-module).
*
* You should only need to update the default test case and/or add more test cases to the "testGroup" object
* Additionally, you should update the "requires" list.
*
* @module yui-powered-module-tests
* @for yui-powered-module
*/
YUI.add('yui-powered-module-tests', function(Y) {
var NAME = 'Yui Powered Module';
//---------------------------------------------------------------------
// Test Group Initialization
//---------------------------------------------------------------------
var testCases = {},
testSuite = new Y.Test.Suite(NAME + ' Test Suite');
//---------------------------------------------------------------------
// Test Cases
//---------------------------------------------------------------------
// string trim test suite (name this something meaningful)
testCases['string-trim'] = new Y.Test.Case({
name: 'String Trim',
//---------------------------------------------
// Setup and tear down
//---------------------------------------------
setUp : function () {
//this.data = {};
},
tearDown : function () {
//delete this.data;
},
//---------------------------------------------
// Special instructions
//---------------------------------------------
_should: {
ignore: {},
error: {
'a call to trim without a parameter should throw TypeError': TypeError
}
},
//---------------------------------------------
// Test Cases
//---------------------------------------------
'a call to trim without a parameter should throw TypeError': function(){
Y.YuiPoweredModule.trim();
}
});
//---------------------------------------------------------------------
// Register Test Cases with the Test Suite
//---------------------------------------------------------------------
for (var tc in testCases) {
if (testCases.hasOwnProperty(tc)) {
testSuite.add(testCases[tc]);
}
}
//---------------------------------------------------------------------
// Runner
//---------------------------------------------------------------------
Y.Test.Runner.setName(NAME + ' Suite Runner');
Y.Test.Runner.add(testSuite);
}, '0.0.1', {
requires: ['test', 'yui-powered-module']
});
/**
* A YUI3 Powered Module.
*
* @module yui-powered-module
* @for some-yui3-powered-application
*/
YUI.add('yui-powered-module', function (Y) {
Y.YuiPoweredModule = {
/**
* A simple method
*/
trim: function(input) {
if (typeof input == 'undefined') {
throw new TypeError('"input" parameter was not provided.')
}
return input.replace(/^\s+|\s+$/g, '');
}
};
}, '0.0.1', {
requires: []
});
@wilmoore
Copy link
Author

@wilmoore
Copy link
Author

YETI QUICKSTART

npm install -g yeti
curl -s https://raw.github.com/gist/2562938/yui-powered-module.js -o yui-powered-module.js
curl -s https://raw.github.com/gist/2562938/yui-powered-module-tests.js -o yui-powered-module-tests.js
curl -s https://raw.github.com/gist/2562938/tests.js -o tests.js
curl -s https://raw.github.com/gist/2562938/tests.html -o tests.html
open tests.html
yeti --server

# in a separate terminal tab
open http://localhost:9000
yeti tests.html # you will be prompted to hit <enter> a second time to run tests
watch yeti tests.html # strongly recommended as opposed to the above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment