How to do it...

Let's perform the following steps to create a Mocha unit test for the authentication middleware of our Express web server:

  1. First, we'll need to create a new /test directory in the root of our Express project where we will keep our test files. We will also need to update our project's tsconfig.json TypeScript configuration file to include our test directory and any .ts files within it:
      {        ...        "include": [          "src/**/*.ts",          "test/**/*.ts"        ],        ...      }
  1. Next, we'll create a new Mocha unit test file, called /test/unit/test-middleware-auth.ts. Note that we created another subdirectory called /test/unit to denote this file as a unit test. We also named the file in a way that represents its logical path in our application, which is

Get MEAN Cookbook 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.