Build a tiny test runner and fix a bug with it
Build a small test kit, then use it to find and fix a bug in cartTotal.
1. assertEqual(actual, expected) does nothing when the values are deeply equal (compare JSON.stringify of both) and throws an Error with a message like expected 0 but got ... when they aren't.
2. test(name, fn) runs fn. If it doesn't throw, log PASS <name>; if it throws, log FAIL <name>: <message>. Also add an <li> with the same text to #report. A failing test must not stop the others.
3. Write at least three tests for cartTotal: two items, one item, and an empty cart (which should be 0). Some will fail. Fix cartTotal so they all pass.
4. After the tests, write <passed> passed, <failed> failed in #summary.
What Check tests
- At least three tests are listed in
#report, all passing - The summary says how many passed and that 0 failed
assertEqualstays silent for equal values, arrays includedassertEqualthrows for different valuestestlogsPASS <name>for a passing testtestlogsFAIL <name>: <message>and doesn't throwcartTotalis fixed
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Your page
Console
Nothing logged yet.