Testing Teardown

Learn about the different methods of tearing down our Jest tests.

What does teardown entail?

Teardown is where we clean up. We don't want any configurations or mocks unknowingly making their way into our next test. This type of spillover can lead to confusing results and bugs that are difficult to track down. We perform teardown in order to wipe the slate clean at different points in our test execution and leave behind a fresh canvas with which to start anew with our next tests.

Global teardown

Our Jest configuration file allows us to add a globalTeardown field, which accepts a string value. The string value represents a path pointing to a file containing our global teardown code. This file exports a single function that we want to call at the end of running all of our test suites. The function ...