Skip to content

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?

JavaScript
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

Guided practice

Practice, not scored

A third assertion is added: assertEqual(labelPrice(3, undefined), "3.00");. Which assertions exercise the default for digits?

Choose one answer

Exit check

Counts toward completion

What does labelPrice(3, 0) return?

Choose one answer

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.

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