Test Setup and Teardown

Learn how to initialize and clean up code before and after running tests in TypeScript.

Before we run a particular test, we may wish to exercise some code beforehand. This may be to initialize a particular variable or to make sure that the dependencies of an object have been set up.

In the same vein, we may wish to execute some code once a particular test has run or even after a full test suite has run. To illustrate this, consider the following class:

Get hands-on with 1400+ tech skills courses.