HTML and CSS Reference
In-Depth Information
Listing 15.20 Appending elements to the document
"test should append HTML to document": function () {
/*:DOC += <div id="myDiv"></div> */
var div = document.getElementById("myDiv");
assertEquals("div", div.tagName.toLowerCase());
}
For the most part, not appending to the document is both slightly faster and
more convenient, because JsTestDriver automatically assigns it to a property on the
test case. Unless we need to pick up elements globally (e.g., by selecting them from
the document) or need elements to render, there usually is no gain in appending the
elements to the document.
15.2.2.3 Getting the Username
Returning to the controller, the problem at hand is expecting handleSubmit to
pick up what the user entered in the form's first text input field and using it as the
username. To do this, we'll first remove the element stub we've been using so far,
and use an actual form instead. Listing 15.21 shows the updated setUp .
Listing 15.21 Embedding a user form in setUp
function userFormControllerSetUp() {
/*:DOC element = <form>
<fieldset>
<label for="username">Username</label>
<input type="text" name="username" id="username">
<input type="submit" value="Enter">
</fieldset>
</form> */
this.controller = Object.create(userController);
dom.addEventHandler = stubFn();
}
Running the test confirms that we're still in the green. With an actual form in
place, we can add the test that expects handleSubmit to read the input field, as
seen in Listing 15.22.
Listing 15.22 Expecting handleSubmit to read username from field
"test should set model.currentUser": function () {
var model = {};
 
Search WWH ::




Custom Search