Wednesday, April 16th, 2008
DOH, let me test my code!
<p>Dustin Machi has posted on DOH, the Dojo Objective Harness which is a testing framework for JavaScript.It can be used with your own Dojo applications, and even without any Dojo at all.
To do this you need to follow a couple of patterns, and Dustin documents them so you can get going.
You end up putting the correct refresh code in your HTML:
-
-
<meta http-equiv="REFRESH" content="0;
-
url=../../../util/doh/runner.html?testModule=company.tests.foo
-
®isterModulePath=company,../../company">
-
You register tests like this:
-
-
doh.register("project.tests.TestGroupA",
-
[
-
{
-
name: "My Function Test [_myfunc()]",
-
timeout: 4000,
-
runTest: function(){
-
var result = _myFunc("a", "b");
-
doh.assertEqual("Foo", result);
-
}
-
}
-
]
-
);
-








What exactly are you testing?
@Mikael: It is for unit testing javascript code. Dojo uses it for unit testing the its core, but really you can use it to test pretty much any js code that you want. You simply need to write a tests that does something and then use doh.assert* to verify the results are what are expected.