JSTAcademy
0 XP
Dashboard
Crash Courses
Automated Testing with Jest
15 min
Basic+200 XP
Crash Courses · Basic

Automated Testing with Jest

Unit tests, mocking, coverage
15 min read+200 XP on completionCert: Quality Assurance
Tap any word in the text below to start reading from there.

# Automated Testing with Jest

Structure

describe groups tests. it (or test) defines a single test case. expect creates the assertion.

Common Matchers

toBe for strict equality. toEqual for deep equality on objects and arrays. toContain for arrays and strings. toThrow for expected errors. toBeTruthy and toBeFalsy.

Mocking

jest.mock replaces an entire module. jest.fn creates a mock function. mockResolvedValue sets the return value for async mocks.

0%