Chapter 9. Toward testable, reactive programs

 

This chapter covers

  • Understanding functional programming’s inherent testability
  • Testing asynchronous code with Mocha.js
  • Exploring the tools for testing observables
  • Understanding the need for using virtual time instead of physical time
  • Introducing RxJS schedulers
  • Refactoring streams to enhance testability

If you’ve been in the software industry for any appreciable amount of time, you’ve likely encountered some form of testing. In production software, there’s no escaping the need for tests (or there shouldn’t be), whether they target newly written code or a system-wide refactoring. Changes to complex applications can easily produce unforeseen consequences in different paths of execution; it’s particularly problematic when multiple developers work with code that they’re not intimately familiar with. For instance, when a user types a negative number in the withdraw field or presses this number rapidly many times, your banking application should handle it gracefully. As you know, in JavaScript, a misspelled variable or a forgotten return statement means that certain execution paths may produce undefined values. These sorts of errors may be obvious or subtle, and no developer—no matter how experienced—is safe from them.

9.1. Testing is inherently built into functional programs

9.2. Testing asynchronous code and promises

9.3. Testing reactive streams

9.4. Making streams testable

9.5. Scheduling values in RxJS

9.6. Augmenting virtual reality

9.7. Summary