Unit tests and integration tests with Mocha

In Chapter 9, Automating Your Development Workflow, we learned the basic details of the unit tests and test-coverage reports with nyc, ts-node, Mocha, and Chai. In this chapter, we are going to learn how to test asynchronous APIs using Mocha and how to combine Mocha with other powerful tools, such as Sinon.JS, SuperTest, and Enzyme:

  • We are going to learn how to write tests for every layer of an application.
  • We are going to start by testing a math library used in the backend.
  • We will then test a web service, which consumes the math library, and a client, which consumes the web service.
  • We will finish the section by writing tests for the graphic user interface and creating some e2e tests.

Get Learning TypeScript 2.x - Second Edition 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.