Jest bundles a test runner, an assertion library, and mocking support into one package with almost no configuration required - which is most of why it's become the default choice for testing JavaScript this year.
function formatPrice(cents) {
return (cents / 100).toFixed(2);
}
test('formats cents as a decimal string', () => {
expect(formatPrice(4999)).toBe('49.99');
});
Testing components, not just functions
import { render, screen } from '@testing-library/react';
test('renders the project title', () => {
render(<ProjectCard title="Site Rebuild" />);
expect(screen.getByText('Site Rebuild')).toBeInTheDocument();
});
Where we've started, realistically
Not every line of every project is covered - that's not a realistic bar for project work under deadline. Pricing logic, form validation, and anything a bug in would be expensive to miss get tests first; purely presentational components come later, if at all.
The three-part shape of almost every test
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
Arrange (set up the inputs), Act (call the function), Assert (check the result) is the pattern underlying nearly every unit test, regardless of framework. Jest's describe/test structure and built-in expect matchers cover the majority of everyday assertions without needing a separate assertion library.
Mocking is where testing gets genuinely useful - and genuinely tricky
A unit test shouldn't actually hit a real database or external API; jest.mock() replaces that dependency with a controlled fake so the test verifies your code's logic, not a third-party service's uptime. The trap to avoid: over-mocking to the point that a test passes even when the real integration would fail - mocking should replace the thing you're not testing, not the thing you are.