Search⌘ K

Grouping, Forcing, and Skipping Tests

Explore how to effectively manage your Jest test suites by grouping related tests with the describe function. Understand how to force specific tests or groups to run using .only, fit, and fdescribe, and learn the implications of skipping tests with xit. This lesson helps you improve test organization and control, essential for maintaining robust Test-Driven Development workflows.

Grouping tests

Within a test specification file, we may want to group our tests into logical sets. Jest uses the function describe for this purpose, as seen in the following tests:

TypeScript 4.9.5
describe("a group of tests", () => {
test("first test", () => {
expect("string value").toEqual("string value");
});
it("second test", () => {
expect("abc").not.toEqual("def");
});
});

Here, we start our tests with the describe function. The describe function is very similar to the test function and also has two parameters.

  • The first parameter is a string value for the name of the group of tests or the test suite.

  • The second parameter is a function containing the set of tests.

Within this describe function, we have a test named "first test" on lines 2–4 and another test named "second test" on lines 5–7.

Note: The second test uses the it function and not the test function.

These two function names are synonymous because the it ...