Unit Test
Add unit tests for price calculation: 100 gets 20 off, 99 does not, and external payment must not participate.
Add unit tests for price calculation: 100 gets 20 off, 99 does not, and external payment must not participate.
1 import { calculateTotal } from "../price";
2
3 test("adds 8% tax", () => {
4 const result = calculateTotal(100, 0.08);
5 expect(result).toBe(108);
6 });↳External services never enter this workspace, so a failure points more directly to the price function.
Check one small responsibility: Boundary inputs such as 100 gets 20 off and 99 gets none directly test the price rule. On failure, look at the calculation rather than guessing about network or database.
Keep outside dependencies controllable: Payment, network, or current time can be isolated or replaced when they make results slow or unstable. Unit tests are fast and precise, but do not prove systems work together.
Add unit tests for the discount calculation: 99 gets no discount and 100 gets 20 off. Do not call real payment or network services; after the change, list both inputs and actual outputs.