Grouping, Forcing, and Skipping Tests
Learn how to group tests using Jest's describe function and how to force or skip specific tests in a group using different keywords.
We'll cover the following...
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:
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
itfunction and not thetestfunction.
These two function names are synonymous because the it ...