HTML and CSS Reference
In-Depth Information
The next test, shown in Listing 15.5, expects setView to be a function.
Listing 15.5 Expecting setView to be a function
"test should have setView method": function () {
Listing 15.6 adds an empty method to pass the test.
Listing 15.6 Adding an empty setView method
(function () {
function setView(element) {}
tddjs.namespace("chat").userFormController = {
setView: setView
}()); Adding a Class
The first actual behavior we'll test for is that the “js-chat” class name is added
to the DOM element, as seen in Listing 15.7. Note that the test requires
the Object.create implementation from Chapter 7, Objects and Prototypal
Inheritance, in lib/object.js to run smoothly across browsers.
Listing 15.7 Expecting the view to have its class name set
TestCase("UserFormControllerSetViewTest", {
"test should add js-chat class": function () {
var controller = Object.create(userController);
var element = {};
assertClassName("js-chat", element);
The first thing that sticks out about this test is that it contains no DOM elements.
It does, however, use the assertClassName assertion, which checks if an element
has the given class name. This assertion is generic, and only checks that the object
defines a string property className and that one of its space separated values
matches the provided string.
Search WWH ::

Custom Search