Categories
JavaScript Answers

What is the difference between describe and it in Jest?

Spread the love

In this article, we’ll look at the difference between describe and it in Jest.

What is the difference between describe and it in Jest?

The difference between describe and it in Jest is that describe lets us divide our test suite into sections.

it is called to create individual tests which is used in the describe callback.

For instance, we write

const myBeverage = {
  delicious: true,
  sour: false,
};

describe('my beverage', () => {
  it('is delicious', () => {
    expect(myBeverage.delicious).toBeTruthy();
  });

  it('is not sour', () => {
    expect(myBeverage.sour).toBeFalsy();
  });
});

to compartmentalize our tests with describe, which we create with it.

We call describe to create a test module by calling it with a callback.

And we call it inside the callback to create individual tests.

expect is run in tests to check if the code being tested returns the expected result.

Conclusion

The difference between describe and it in Jest is that describe lets us divide our test suite into sections.

it is called to create individual tests which is used in the describe callback.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *