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.
Test mindset — tiny assertions, AAA, red→green→refactor is a free JavaScript Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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

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");

Arrange–Act–Assert
AAA keeps tests readable: prepare data, call the function, then check the result.
// AAA: Arrange → Act → Assert
// Arrange: prepare inputs
function sum(a, b) { return a + b; }
const a = 2;
const b = 4;
// Act: call the function
const result = sum(a, b);
// Assert: compare
assertEqual(result, 6, "sum returns a + b");

Red→Green→Refactor
Write a failing test (red), make it pass (green), then clean the code (refactor).
// Red → Green → Refactor with a tiny example
// 1) Red: write a failing test (expect wrong implementation)
function greet(name) { return "Hi " + name; } // simple implementation
// Intentionally failing expectation first (red)
assertEqual(greet("Ayla"), "Hello Ayla", "greet says Hello"); // likely fails
// 2) Green: fix the code to satisfy the test
function greetFixed(name) { return "Hello " + name; }
assertEqual(greetFixed("Ayla"), "Hello Ayla", "greet says Hello (fixed)");
// 3) Refactor: improve code without changing behavior
function greetRefined(name) {
const cleaned = String(name).trim();
return "Hello " + cleaned;
}
assertEqual(greetRefined(" Ayla "), "Hello Ayla", "greet trims input");

Behavior-focused names
Name checks by what the function should do: boundaries and typical cases.
// Clear names describe behavior, not internals
function isAdult(age) { return age >= 18; }
assertEqual(isAdult(18), true, "isAdult returns true at boundary 18");
assertEqual(isAdult(17), false, "isAdult returns false below boundary");

Tiny, focused tests
Tips:
- Keep tests tiny and focused (one idea each).
- Test happy path and one boundary.
- Prefer pure functions for easy testing.
- Automate later with Jest/Vitest; mindset first.

AAA pattern quiz
Quick check: AAA pattern.

Recap
Recap: Use a tiny assert, follow AAA, and iterate Red → Green → Refactor. Start small—clarity beats complexity for beginners.

Frequently asked questions
Is the “Test mindset — tiny assertions, AAA, red→green→refactor” lesson free?
Yes — the full text of “Test mindset — tiny assertions, AAA, red→green→refactor” is free to read here on the web, and the JavaScript Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “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. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start JavaScript Academy?
No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Test mindset — tiny assertions, AAA, red→green→refactor” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this JavaScript Academy lesson?
Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Test mindset — tiny assertions, AAA, red→green→refactor
- Linting with ESLint; Prettier formatting
- CI basics — run lint/test on every push