O'Reilly logo

Node.js in Practice by Alex Young and Marc Harter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required