TAILIEUCHUNG - Test Driven JavaScript Development- P17

Test Driven JavaScript Development- P17:This book is about programming JavaScript for the real world, using the techniques and workflow suggested by Test-Driven Development. It is about gaining confidence in your code through test coverage, and gaining the ability to fearlessly refactor and organically evolve your code base. It is about writing modular and testable code. It is about writing JavaScript that works in a wide variety of environments and that doesn’t get in your user’s way. | Polling for Data 313 Next up Listing makes sure the url property is set on the poller. In order to make this assertion we need a reference to the poller object so the method will need to return it. Listing Expecting the url property to be set test should set url property on poller object function var poller url assertSame url Implementing this test requires two additional lines as in Listing . Listing Setting the URL function poll url options var poller url return poller The remaining tests will simply check that the headers callbacks and interval are set properly on the poller. Doing so closely resembles what we just did with the underlying poller interface so I ll leave writing the tests as an exercise. Listing shows the final version of . Listing Final version of function poll url options var poller url options options return poller poll Please purchase PDF Split-Merge on to remove this watermark. From the Library of 314 Streaming Data with Ajax and Comet Comet Polling will definitely help move an application in the general direction of live by making a more continuous data stream from the server to the client possible. However this simple model has two major drawbacks Polling too infrequently yields high latency. Polling too frequently yields too much server load which may be unnecessary if few requests actually bring back data. In systems requiring very low latency such as instant messaging polling to keep a constant data flow could easily mean hammering servers frequently enough to make the constant requests a scalability issue. When the traditional polling strategy becomes a problem