public
Created

YUI3 Test Skeleton Setup: for testing your YUI3 powered modules

  • Download Gist
tests.html
HTML
1 2 3 4 5 6 7 8 9
<!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>
tests.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
// 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();
});
yui-powered-module-tests.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
/**
* 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']
});
yui-powered-module.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/**
* 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: []
});

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.