6 Testing and debugging TypeScript

 

This chapter covers

  • Debugging TypeScript code using Visual Studio Code and the Node.js debugger
  • Using a linter to find problems in code the com piler won’t detect
  • Writing and executing unit tests on TypeScript code

In this chapter, I continue the theme of TypeScript development tools started in chapter 5, which introduced the TypeScript compiler. I show you the different ways that TypeScript code can be debugged, demonstrate the use of TypeScript and the linter, and explain how to set up unit testing for TypeScript code.

6.1 Preparing for this chapter

For this chapter, I continue using the tools project created in chapter 5. No changes are required for this chapter.

Tip

You can download the example project for this chapter—and for all the other chapters in this book—from https://github.com/manningbooks/essential-typescript-5.

Open a new command prompt and use it to run the command shown in listing 6.1 in the tools folder to start the compiler in watch mode using the tsc-watch package installed in chapter 5.

Listing 6.1 Starting the compiler
npm start

The compiler will start, the TypeScript files in the project will be compiled, and the following output will be displayed:

7:04:50 AM - Starting compilation in watch mode...
7:04:52 AM - Found 0 errors. Watching for file changes.
Message: Hello, TypeScript
Total: 600

6.2 Debugging TypeScript code

6.2.1 Preparing for debugging

6.2.2 Using Visual Studio Code for debugging

6.2.3 Using the integrated Node.js debugger

6.2.4 Using the remote Node.js debugging feature

6.3 Using the TypeScript linter

6.3.1 Disabling linting rules

6.4 Unit testing TypeScript

6.4.1 Configuring the test framework

6.4.2 Creating unit tests

6.4.3 Starting the test framework

Summary

sitemap