All the tests passed with green checks, yet the checkout discount is clearly wrong—did the test just run the code without checking the final amount?
An assertion is a check inside a test that verifies whether the actual result matches the expected result, failing immediately when it does not.·When testing a “30 off 200+” rule, the test must assert the final total equals 170; running the function with no assertion, or only asserting the total is above 0, still passes when a bug returns 200. Assertions judge each outcome automatically, though an assertion with the wrong expectation can still let bugs through.
Review the assertions in the checkout discount tests: replace loose non-empty checks with exact assertions on the final total and visible notice, then introduce a quick bug once to verify the assertion actually fails.
What no assertion, a weak assertion, and an exact assertion report on the same bug
discount.test.tsRule: 30 off 200+
1test('200 order gets 30 off', () => {
2 const total = calcTotal(200)
3 expect(total).toBe(170)
4})
↳The exact assertion pins the expectation to 170 and reports Expected 170 / Received 200; toggle to Fixed code to verify it turns green.
Two habits that make assertions trustworthy
Separate “it ran” from “it verified the outcome”: A test with no assertion—or only loose checks like toBeTruthy() or total > 0—turns green as long as nothing crashes. Assert the concrete result users rely on, such as the exact total, saved record, or error banner.
Read Expected vs. Received before editing: When an assertion fails, the runner prints Expected beside Received. Check which side disagrees with the requirement: fix the app code when actual output is wrong, and update the assertion only when the requirement changed.
Quick checkChoose the best answer
A checkout function should take 30 off orders of 200 or more, but a bug returns 200 for a 200 order. Which assertion reliably catches it?