Search⌘ K
AI Features

Testing Setup

Explore how to configure Jest test environments using global setup, setup files, and setup hooks. Understand how to prepare context and dependencies for effective and isolated testing, enhancing test reliability and scope control.

What does test setup entail?

Test setup is a series of configurations and hooks that we defined, which create the environment we want to run our tests inside. Most software requires some added context to run. For instance, a server might require a seeded database, and a client might require user authentication. Both a server and a client may need additional packages installed in order to be testable with Jest. Test setup is where we get to do all of this.

Global setup

We can configure a global Jest setup through the Jest config file. In our Jest config, we have access to a globalSetup field, which points to a string—the path to the file holding our global setup configuration. This file exports a function ...