How to Run a Specific Test Suite In Jest

Chandler Barlow
2 min readJul 28, 2021

--

Often when practicing test driven development you will have multiple unit tests written for a project. All of these tests ensure that your code is written correctly and that it is free of errors. Practicing strong testing helps us, as developers, catch bugs during the development process rather than during deployment.

This is well and good but as projects get larger and larger over time it can be frustrating to wait for all of your test suites to run. Tests sometimes take precious seconds to run. Seconds might seem negligible but often theses tests are run over and over during the development process. These seconds build up and add on to the already frustrating debugging phase of development. Waiting for all the tests to pass can be especially annoying if you’re focused on a specific function or component within your project. Sometimes you’re stuck waiting on a multitude of unrelated tests to run while debugging one specific item.

Luckily Jest provides functionality to run specific test suites within your project. This is accomplished with a fairly straight forward command.

Run a single test suite

This will run any suite with a matching label. For example consider this implementation of bubble sort.

Bubble sort implementation

What would it look like if we wanted to only run the below test suite?

Bubble Sort tests

We would simply run the following.

The command to run the test suite

Jest is an incredibly intuitive and effective testing library for JavaScript. I hope that this tiny tutorial helps out anyone taking their first steps with Jest.

Thanks for reading!

--

--

Chandler Barlow
Chandler Barlow

Written by Chandler Barlow

Fullstack Developer at Irys / JavaScript Junkie / Creative Coder

No responses yet