AAA Pattern

Arrange-Act-Assert: the standard structure for writing clear, readable tests. Each test should have one of each phase.

Syntax

testing
// Arrange → Act → Assert

Example

testing
test("calculates total with discount", () => {
  // Arrange
  const cart = new Cart();
  cart.add({ price: 100, qty: 2 });
  const discount = 0.1;

  // Act
  const total = cart.calculateTotal(discount);

  // Assert
  expect(total).toBe(180);
});