HTML and CSS Reference
In-Depth Information
The test cases (or test suite if you will) built in this chapter provide some insight
into the kind of tests TDD leaves you with. Even with close to 100% code coverage
(every line of code is executed by the tests), we have several holes in tests; more tests
for cases when things go wrong—methods receive the wrong kind of arguments, and
other edge cases are needed. Even so, the tests document our entire API, provides
decent coverage, and makes for an excellent start in regards to a more solid test suite.
12.8 Summary
In this chapter we have used tests as our driver in developing a higher level API
for the XMLHttpRequest object. The API deals with certain cross-browser is-
sues, such as differing object creation, memory leaks, and buggy send methods.
Whenever a bug was uncovered, tests were written to ensure that the API deals
with the issue at hand.
This chapter also introduced extensive use of stubbing. Even though we saw
how stubbing functions and objects could easily be done manually, we quickly
realized that doing so leads to too much duplication. The duplication prompted us
to write a simple function that helps with stubbing. We will pick up on this idea
in Chapter 16, Mocking and Stubbing, and solve the case we didn't solve in this
chapter; stubbing functions that will be called multiple times.
Coding through tddjs.ajax.request and friends, we have refactored
both production code and tests aggressively. Refactoring is perhaps the most valu-
able tool when it comes to producing clean code and removing duplication. By
frequently refactoring the implementation, we avoid getting stuck trying to come
up with the greatest design at any given time—we can always improve it later,
when we understand the problem better. As food for thought, we rounded off by
discussing a refactoring idea to further improve the API.
The end result of the coding exercise in this chapter is a usable, yet hardly
complete, “ajax” API. We will use this in the next chapter, when we build an
interface to poll the server and stream data.
Search WWH ::

Custom Search