L09 Tests and configuration
17 minSuggested first: L08 Search and symbol navigation
Outcome
Read setup, action, and assertion in a test and distinguish an explicit option from its default.
Learn
Tests describe expected behavior under specific inputs. A test that passes an option can't, by itself, establish what happens by default. Confirm an expectation against the source at the same revision. A regression test covers a particular case that should keep working.
Worked example
Which of the two assertions tells you about the default for digits?
function labelPrice(amount, digits = 2) {
return amount.toFixed(digits);
}
assertEqual(labelPrice(3, 1), "3.0");
assertEqual(labelPrice(3), "3.00");
Predict first, then show the worked explanation
The default applies only when digits is absent or undefined. The first test chooses 1
explicitly, so it demonstrates an override. The second omits the argument, so it's the one that
exercises the default; reading the default parameter on line 1 confirms it.
Practice and check
Common mistake
Using a single assertion to claim how every input behaves. State the tested input and configuration before you generalize.
Practice on a real repository
The puzzle below asks about a default in a different language. Read the prompt before searching, and select the kind of evidence it asks for.
- Falling back to a string for an inferred typeFind · Easy · pallets-click
Related topics: Configuration and defaults, Command-line apps
Practice is optional. Solving a puzzle doesn't complete a lesson, and lessons never change a puzzle's points.
References
- JavaScript Guide (MDN)
- Options (Click documentation)