example qunit tests
already has qunit and its css linked already. sample test provided. useful as a template.
by ernestohs
HTML
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css">
<script src="http://code.jquery.com/qunit/git/qunit.js"></script>
<script src="http://sugarjs.com/release/1.3.7/sugar-1.3.7-full.min.js"></script>
<h1 id="qunit-header">Unit Tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture"></div>
JavaScript
function ageCalculate(date) {
date = date.split("/");
var bMonth = parseInt(date[1]) - 1;
var bDay = parseInt(date[0]);
var bYear = parseInt(date[2]);
var age;
var now = Date.create();
var tday = now.getDate();
var tmo = now.getMonth();
var tyr = now.getFullYear();
if (tmo > bMonth) {
age = tyr - bYear;
} else if (tmo >= bMonth && tday >= bDay) {
age = tyr - bYear;
} else {
age = tyr - bYear - 1;
}
return "(" + age + " años de edad)";
};
// 2 tests - okay is always true and equals (assert)
test("Test a basic age computation", function () {
var expected = "(32 años de edad)";
var actual = ageCalculate('08/14/1980');
equal(expected, actual, "We expect value to be hello");
});