Separate Concerns

The test list now has one incomplete test, “printReport prints the results in sorted order,” which seemed like a good test at the end of the strategic design. But looking at the code we’ve designed so far, that appears like a giant step. We need to break it into smaller functions. Print and sort are two separate concerns—a good design keeps separate concerns apart. Also, we don’t want printReport to write to the console; it’s better to send the data to the caller so they can decide where to print it. Let’s jot down the tests that just emerged:

  • …
  • printReport prints the results in sorted order
  • printReport sends price, errors once all responses arrive
  • printReport does not send before all responses arrive
  • printReport ...

Get Test-Driving JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.