Chapter 10. Tests: The key to confident code

This chapter covers

  • Assertions, custom assertions, and automated testing
  • Ensuring things fail as expected
  • Mocha and TAP
  • Testing web applications
  • Continuous integration
  • Database fixtures

Imagine that you wanted to add a new currency to an online shop. First you’d add a test to define the expected calculations: subtotal, tax, and the total. Then you’d write code to make this test pass. This chapter will help you learn how to write tests by looking at Node’s built-in features for testing: the assert module and test scripts that you can set in your package.json file. We also introduce two major test frameworks: Mocha and node-tap.

Introduction to testing

This chapter assumes you ...

Get Node.js in Practice 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.