HTML and CSS Reference
In-Depth Information
The function simply loops all the properties of the test object, prepends function
property identifiers with “test,” and delegates to the original TestCase . Listing
17.2 , shows a test originally from Chapter 12, Abstracting Browser Differences: Ajax,
using the enhanced test case.
Listing 17.2 Using the enhanced test case to improve test name clarity
testCaseEnhanced("RequestTest", {
/* ... */
"should obtain an XMLHttpRequest object": function () {
ajax.get("/url");
assert(ajax.create.called);
}
/* ... */
});
17.1.2 Structure Tests in Setup, Exercise, and Verify Blocks
White space can be used to underline the inherent setup/exercise/verify structure
of tests. Listing 17.3, originally from Chapter 15, TDD and DOMManipulation: The
Chat Client, shows a test for the user form controller that expects the handle-
Submit method to notify observers of the submitted user name. Notice how blank
lines separate each of the setup/exercise/verify phases of the test.
Listing 17.3 Formatting tests with blank lines to improve readability
"test should notify observers of username": function () {
var input = this.element.getElementsByTagName("input")[0];
input.value = "Bullrog";
this.controller.setModel({});
this.controller.setView(this.element);
var observer = stubFn();
this.controller.observe("user", observer);
this.controller.handleSubmit(this.event);
assert(observer.called);
assertEquals("Bullrog", observer.args[0]);
}
 
Search WWH ::




Custom Search