JsUnit is a JavaScript framework similar to JUnit and NUnit for unit testing JavaScript code.
Once JsUnit is installed on your development computer, browse to the testRunner.html page included with JsUnit, that is, http://localhost/jsunit/testRunner.html. Then enter the URL to your test page and click the button to run the tests.
In the test page, define one or more functions that began with the name 'test', as in 'testMyCode'. The testRunner page will call every function that begins with the name 'test'.
Write your 'test' functions to call various 'assert' functions defined by JsUnit. They include:
assert("true should be true", true);
assertTrue("true should be true", true);
assertFalse("false should be false", false);
assertEquals("1 should equal 1", 1, 1);
assertNotEquals("1 should not equal 2", 1, 2);
assertNull("null should be null", null);
assertNotNull("1 should not be null", 1);
assertUndefined("A declared but unassigned variable should have the undefined value", myVar);
assertNotUndefined("1 should not be undefined", 1);
assertNaN("a string should not be a number", "string");
assertNotNaN("1 should not be not a number", 1);
And, of course, be sure to include JsUnit in your test page.
<script language="JavaScript" type="text/javascript" src="/jsunit/app/jsUnitCore.js"></script>
Example,
function testMyCode()
{
assertNotUndefined("MyGlobal must be defined", MyGlobal);
assertEquals("1.0", MyCode.VERSION);
assertNotNull(MyObject);
}
http://www.jsunit.net/