Test Invalid Negative Numbers and Wrong Types
Scenario
Audit three invalid-input tests for canBook(freeSeats).
Try it yourself
Compare negative, string, and null inputs against the documented INVALID_FREE_SEATS policy.
| Case | Result |
|---|---|
| canBook(-1) | Select a choice above to see what happens. |
| canBook("2") | Select a choice above to see what happens. |
| canBook(null) | Select a choice above to see what happens. |
Reveal the explanation
- canBook(-1)
Must raise/return INVALID_FREE_SEATS (not silent false).
- canBook("2")
Must raise/return INVALID_FREE_SEATS (blocks silent string coercion).
- canBook(null)
Must raise/return INVALID_FREE_SEATS (explicit missing-data rejection).
Always assert the exact error code or message—not just "throws anything"—so a random crash cannot masquerade as a passing validation test.
Download shared test cases
Your turn
Write 3 invalid-input fixture cases for canCheckoutBook(isAvailable, borrowedCount) expecting INVALID_CHECKOUT_INPUT.
Common mistake Asserting only "throws any error" without checking the error code string.
Check your work
(true, -1), ("yes", 1), and (true, null) all produce INVALID_CHECKOUT_INPUT.
Quick check
This browser could not save your progress. Changes last until you leave the page.