HTML and CSS Reference
In-Depth Information
The tests now all pass. The observe method could probably benefit from type
checking this.observers.observe like we did with notify in dispatch .
You might also have noticed that there are no tests asserting what happens if either
topic or events is not what we expect it to be. I urge you to cover those paths
as an exercise.
Both topic and observer are actually checked for us by observable.
observe , but relying on it ties the client more tightly to its dependencies. Be-
sides, it's generally not considered best practice to allow exceptions to bubble a
long way through a library, because it yields stack traces that are hard to debug for
a developer using our code.
13.4.5 Server Connection
So far, all we have really done is to wrap an observable for a given data format.
It's time to move on to connecting to the server and making it pass response data
to the dispatch method. The first thing we need to do is to obtain a connection,
as Listing 13.55 specifies.
Listing 13.55 Expecting connect to obtain a connection
TestCase("CometClientConnectTest", {
setUp: function () {
this.client = Object.create(ajax.cometClient);
this.ajaxPoll = ajax.poll;
},
tearDown: function () {
ajax.poll = this.ajaxPoll;
},
"test connect should start polling": function () {
this.client.url = "/my/url";
ajax.poll = stubFn({});
this.client.connect();
assert(ajax.poll.called);
assertEquals("/my/url", ajax.poll.args[0]);
}
});
 
Search WWH ::




Custom Search