//The goal of gUnit is to allow inline unit test writing.
//by keeping test code relevant and not seperated we can
//ensure that we are always writing unit tests, for even
//small tasks.
//
//This is good, because it will allow us to be more responsive
//to any problems with interactions.
var cmg = {};
(function(cmg){
cmg.gUnit = function(testfunc){
var tests = {};
var didipass = true;
var displaydiv = $('<div/>');
for (var mainfunc in testfunc)
{
if(typeof(testfunc[mainfunc]) == "function"){
$('<h2/>',{
text: mainfunc
}).appendTo(displaydiv);
for (var func in new testfunc[mainfunc])
{alert(func);
var testfunction = new testfunc[mainfunc];
if(typeof(testfunction[func]) == "function"){
if(func.slice(0,4) == "test"){
tests[func] = testfunction[func]();
if(tests[func] == false){didipass = tests[func]};
$('<li/>',{
text: func.slice(4, func.length).replace(/_/g," ") + ' : ' + tests[func]
}).appendTo(displaydiv);
}
}
}
}
}
$('<h1/>',{
text: 'did i pass: ' + didipass
}).prependTo(displaydiv);
var testlist = $('<ul/>');
testlist.appendTo(displaydiv);
displaydiv.appendTo("body");
};
})(cmg);
//simple jQuery document.ready wrapper that allows
//for even the smallest snippets to be unit tested
(function($){
function _$(){}
_$.prototype = {
init: function() {
//do your stuff here, even for a document
//ready
$("div").text("winnder winner");
//write test inline through a prototype using
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.