HTML and CSS Reference
In-Depth Information
Listing 11.8
Missing
addObserver
method
chris@laptop:~/projects/observable
$
jstestdriver --tests all
E
Total 1 tests (Passed: 0; Fails: 0; Errors: 1) (0.00 ms)
Firefox 3.6.3 Linux: Run 1 tests \
(Passed: 0; Fails: 0; Errors 1) (0.00 ms)
Observable.addObserver.test \
should store function error (0.00 ms): \
observable.addObserver is not a function
()@http://localhost:4224/.../observable_test.js:8
Listing 11.9 adds the missing method.
Listing 11.9
Adding the
addObserver
method
function addObserver() {
}
Observable.prototype.addObserver = addObserver;
With the method in place, Listing 11.10 shows that the test now fails in place
of a missing
observers
array.
Listing 11.10
The observers array does not exist
chris@laptop:~/projects/observable
$
jstestdriver --tests all
E
Total 1 tests (Passed: 0; Fails: 0; Errors: 1) (1.00 ms)
Firefox 3.6.3 Linux: Run 1 tests \
(Passed: 0; Fails: 0; Errors 1) (1.00 ms)
Observable.addObserver.test \
should store function error (1.00 ms): \
observable.observers is undefined
()@http://localhost:4224/.../observable_test.js:10
As odd as it may seem, Listing 11.11 now defines the
observers
array inside
the
addObserver
method. Remember, when a test is failing, we're instructed to
do
the simplest thing that could possibly work
, no matter how dirty it feels. We will
get the chance to review our work once the test is passing.