describe, it and expect
phrase
say it: “dih-SKRIBE, IT and ek-SPEKT” /dɪˈskraɪb ɪt ænd ɪkˈspɛkt/
Three functions test files use: one to group related tests, one to write a single test, and one to check a result.
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([]);
});
});
In a sentence
- “With describe, it and expect, my test file reads almost like a sentence: the cart, it starts empty, expect zero items.”
- “I grouped the playlist tests with describe, it and expect so the report lists them under one heading.”
Level: Apprentice · More JavaScript terms at this level
Updated