concept test in category coffeescript

appears as: tests, tests, test, A test, A test, The test, The test, test, The tests, The tests
CoffeeScript in Action

This is an excerpt from Manning's book CoffeeScript in Action.

Without types, how do you have confidence that your program works correctly? You get confidence by writing tests. Good tests for the DuckRace class will show how it should be used and demonstrate that it works correctly when used as intended. There’s more about testing in chapter 10.

This chapter presents and encourages a test-driven approach to development and leads you through the creation of your own tiny test framework. In practice, it’s more likely you’d use an existing test framework, but your understanding will be deeper if you go through the steps to build a tiny framework. The techniques for writing unit tests, dealing with dependencies, testing asynchronous callback-driven code, and structuring tests can be applied in other ways. First of all, why are tests important and why do you need automated tests? Why can’t you just test manually?

createHttp = ->
  http =
    get: (options, callback) ->
      callback()
      @
    on: (event, callback) ->
      # do nothing
  http

fact 'this test uses a http double' ->
  http = createHttp()
  # the rest of the test goes here
Figure 10.1. Tests are evidence that your program works.