Chapter 9. Testing Express applications

 

This chapter covers

  • How testing helps you to be more confident about your code’s behavior
  • Common testing practices
  • Running tests in Node.js with Mocha and Chai
  • Using Mocha and SuperTest and Cheerio

Writing reliable code can be difficult. Even small software can be too complex for one person, which can create bugs. Developers have come up with a number of tricks to try to squash these errors. Compilers and syntax checkers automatically scan your code for potential bugs; peer code reviews let other people look at what’s written to see if they can spot errors; style guides can keep teams of developers on the same page. These are all helpful tricks you play that keep your code more reliable and bug-free.

Another powerful way to tackle bugs is with automated testing. Automated testing lets you codify (literally!) how you want your software to behave and lets you say, “My code works!” with much more confidence. It lets you refactor code without worrying if you broke something, and it gives you easy feedback about where your code fails.

You want these benefits for your Express applications. By the end of this chapter, you’ll

9.1. What is testing and why is it important?

9.2. Introducing the Mocha testing framework

9.3. Testing Express servers with SuperTest

9.4. Summary