describe, it and expect

Group tests, define tests, and assert results.

What do describe, it and expect do?

In Jest and Vitest, describe groups tests, it defines the test, and expect(...).toBe(...) makes the assertions.

describe('cart', () => {
  it('starts empty', () => {
    expect(new Cart().items).toEqual([]);
  });
});

Level: Apprentice · More JavaScript terms at this level

Updated