JsTestDriver only executes methods that start with the prefix "test". This is a naming convention to enable you to write helper methods on the same object that aren't executed as tests.
There are also two reserved method names setUp
and tearDown
, which will be executed before and after each test respectively.
You can even use spaces in your test names, which makes your tests nicely readable, for example:
TestCase("AjaxCreateTest", {
setUp : function() {
this.subject = new MyAjaxCode();
this.stubXHR();
},
tearDown : function() {
this.restoreXHR();
},
stubXHR : function() {
// stub global objects to intercept Ajax calls
},
restoreXHR : function() {
// restore global state
},
"test should say hi" : function() {
assertEquals("Hi", this.subject.sayHi());
}
}
In the example above there's only one test, the rest are helper methods.
I can recommend Sinon.JS for helping you stub your Ajax calls (see "Fake XHR") and for further examples.