Structure

Creating tests

Create a test by using the test() funtion or its alias it().

circle-info

Will be created a top-level scope.

test('', () => {});

// Or

it('', () => {});

Using describe()

Create a block that groups together several related tests.

This isn't required - you can write the test blocks directly at the top level. But this can be handy if you prefer your tests to be organized into groups.

You can also nest describe blocks if you have a hierarchy of tests.

circle-info

A describe block also defines a new scope for variables and other functions like beforeAll(), beforeEach(), afterAll() and afterEach().

describe('', () => {
    it('', () => {});
    it('', () => {});
    
    describe('', () => {
        it('', () => {});
    });
});

You define multiple values for a specific test instead of creating multiple test functions with different values.

The .each modifier offers few different ways to define a table of the test cases.

Run specific test

To run only specific test or block of tests use:

Skip tests

To skip tests or block of tests, just append skip modifier right after test | it | describe.

Use the .concurrent modifier to run test concurrently.

You can't use this modifier in describe() blocks.

circle-exclamation
circle-info

Use the maxConcurrencyarrow-up-right configuration option to prevent Jest from executing more than the specified amount of tests at the same time.

Last updated