Putting Jest to Rest (VS Code): How to stop Jest from running all the time

Why this

Have you found yourself with Jest tests running all the time, in other words, Jest is watching you? Sometimes we want this, especially when we are testing our application but other times we just want to code. Additionally, Jest running consumes a lot of resources and could slow down your working on VS Code. So how do we stop this?

Solution

In this guide, I am using Visual Studio Code version 1.86.2 (user setup). Click the hamburger menu on your VS Code, Choose file, choose preferences and then choose settings. On the settings page scroll to Jest or simply search for Jest. In the Jest: Run Mode Colors click the link Edit in settings.json and add the following code and save.

{"jest.runMode": "on-demand"}

The jest.runMode configuration option in Jest allows developers to specify the mode in which Jest runs tests. It influences when and how tests are executed, providing flexibility in aligning Jest with various development workflows.

jest.runMode accepts four values: watch , on-demand, on-save and deferred .

watch - Triggers tests automatically.

on-demand - Allows running tests only when triggered.

on-save - Triggers tests when a files is saved.

If you want to learn more about jest run modes here is more information .