0Pricing
JavaScript Academy · Lesson

Test mindset — tiny assertions, AAA, red→green→refactor

Build the habit of writing tiny tests: understand assertions, Arrange–Act–Assert, and the red→green→refactor loop.

Why test mindset?

Goal: Think in tiny, reliable tests.

  • Small assert to check results
  • AAA: Arrange → Act → Assert
  • Red → Green → Refactor loop
  • Name tests by behavior
Test mindset — tiny assertions, AAA, red→green→refactor — illustration 1

A tiny assertion

A tiny assertEqual prints pass/fail. This mirrors what real test frameworks do.

// Minimal assertEqual for quick checks
function assertEqual(actual, expected, name) {
  if (actual === expected) {
    console.log("✅", name);
  } else {
    console.log("❌", name, "expected:", expected, "got:", actual);
  }
}

// Demo check
assertEqual(2 + 3, 5, "adds numbers");
Test mindset — tiny assertions, AAA, red→green→refactor — illustration 2

All lessons in this course

  1. Test mindset — tiny assertions, AAA, red→green→refactor
  2. Linting with ESLint; Prettier formatting
  3. CI basics — run lint/test on every push
← Back to JavaScript Academy