Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
The `describe` Block | Using a Test Automation Framework
Introduction to QA Automation Testing
course content

Course Content

Introduction to QA Automation Testing

Introduction to QA Automation Testing

1. Introduction to Automation Testing
2. Using a Test Automation Framework
3. Browser Automation with Selenium
4. Intro to Intermediate Automation Testing

bookThe `describe` Block

Summary

Sometimes, we might have many tests in a single Test Script, which can become unorganized and hard to manage. For an example, lets create a new file called math.js with a Math class in it:

This class contains four methods and we write multiple test cases for each method. Since the test cases are related to a single class, therefore, conventionally we would store all the test cases related to it in a single file called math.test.js:

However, as you might notice, this can become confusing and unorganized since it contains test cases for multiple different methods. If we run the above tests using the verbose flag, you will see that the tests are all piled up in a sequence with no distinction.

In such situations it is imperative to group together the related test cases using describe blocks:

Using the above syntax, we can group together the test cases of each method:

Now the code looks more organized, and if we run the tests with the verbose flag, you will notice that the output is more hierarchical as well, making it easier to see the different test cases for each method.

It is also important to note that we can nest describe blocks to further organize the hierarchy of Test Cases:

The describe blocks also help in defining the scope of each Test Case. We will see some uses of the scopes of test cases in later topics.

Apart from that, since we typically group together test cases in a describe block, each describe block is referred to as a Test Suite in this case. It is important to note that, in other programming languages, a whole Test Script is typically referred to as a Test Suite.

What can be the describe block used for in Jest? (Select all that Apply)

What can be the describe block used for in Jest? (Select all that Apply)

Select a few correct answers

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 6
some-alt