Lesson 15 — Conditionals: Branches That Cover the World · Practical QA
LESSON VIEW
F-02 · BASIC · PRACTICAL QA

Lesson 15 — Conditionals: Branches That Cover the World

Objective: Conditionals — how test code decides. Valid phone or refused? Standard price, Deep price, or no price at all? Every branch you meet in the FreshNest lab is one of these three shapes. You will write all three.

⏱ ≈5 min full lesson · Converted from the F-02 module deck · English edition — Español · العربية · বাংলা in translation

⚡ Key Points

  • Branches must cover the world — if runs its block when the condition is true; else runs when it is false; else if chains further tests in order.
  • Valid phone, or refused — RUN IT: the phone rule from the requirements — exactly 10 digits.
  • Operators: compare and combine — The comparison operators: === (equal), !== (not equal), <, >, <=, >=.
  • Three services, three paths — RUN IT, then break it on purpose: change the Deep multiplier and watch the wrong branch produce a wrong price.
  • The answer — It returns 165. Notice the order of operations the BRANCHES impose: the shared standard computation happens before the f…
  • Spot the bug — SPOT THE BUG: this guard is meant to stop a booking with an empty name.

📖 Read

In ~5 minutes: conditionals — how test code decides. Valid phone or refused? Standard price, Deep price, or no price at all? Every branch you meet in the FreshNest lab is one of these three shapes. You will write all three.

Branches must cover the world: if runs its block when the condition is true; else runs when it is false; else if chains further tests in order. The condition is any boolean expression. The discipline that matters for testers: the branches must COVER the world — every input lands in exactly one branch, and you should be able to name the input that lands in each. An uncovered input is an untested behaviour.

Valid phone, or refused: RUN IT: the phone rule from the requirements — exactly 10 digits. Then edit: try '609555014' (9 digits) and '16095550142' (11) and re-run each time. All three runs together ARE case VAL-003 — the boundary case from the test-case document — expressed as code. Code: const phone = '6095550142'; | if (phone.length === 10) { | console.log('accepted'); | } else { | console.log('rejected: phone must be exactly 10 digits'); | }

Operators: compare and combine: The comparison operators: === (equal), !== (not equal), <, >, <=, >=. Always === in tests — the single = is assignment, not comparison (the spot-the-bug card ahead lives on exactly this). Logical operators combine conditions: && (both), || (either), ! (not). A booking is submittable when name is non-empty AND phone is 10 digits: two facts, one &&.

Three services, three paths: RUN IT, then break it on purpose: change the Deep multiplier and watch the wrong branch produce a wrong price. This three-way branch is FreshNest pricing itself — Standard adds the bedroom steps, Deep multiplies, and Move-Out has NO price: the branch exists to refuse to invent one. Code: function priceFor(service: string, beds: number): number | null { | const standard = 140 + (beds - 2) * 30; | if (service === 'standard') { | return standard; | } else if (service === 'deep') { | return standard * 1.5; | } else { | return null; // move-out: quoted individually, never priced here | } | } | console.log(priceFor('deep', 2), priceFor('standard', 3), priceFor('move-out', 3));

The answer: It returns 165. Notice the order of operations the BRANCHES impose: the shared standard computation happens before the fork, so every service agrees on the base. When you reach LAB-3's pricing table, this function is the oracle those rows are checked against.

Spot the bug: SPOT THE BUG: this guard is meant to stop a booking with an empty name. It never stops anything. Find the single character that breaks it.

The answer: The bug is = where === belongs: assignment instead of comparison, so the condition is never true and the guard is decoration. Guard clauses are the framework's favourite conditional shape: check the refusal FIRST and exit early, so the happy path reads straight down without nesting. You will meet this shape in every page object in LAB-4.

Complete the guard: COMPLETE the guard clause in this page-object method: refuse to submit when the phone is not exactly 10 digits, before any clicking happens.

The answer: Keep the if/else-if chain. Readability is a testing property: the next human must be able to see that move-out refuses. You have finished this module when: you can write the phone branch, the three-service pricing branch, and a guard clause — and name an input that lands in every branch you write.

Write the three FreshNest branches (phone validity, service pricing with the move-out refusal, one guard clause) and name a covering input for every branch.