Add tests for the coupon discount helper

React · React · beginner · greenfield

Adds unit-test coverage for `couponDiscount` ahead of the checkout revamp: the WELCOME10 happy path, the unknown-code path, and the zero-subtotal edge case are all exercised. All three tests pass.

Requirements

Files touched

--- src/pricing/couponDiscount.test.js
+import { couponDiscount } from './couponDiscount';
+
+describe('couponDiscount', () => {
+  it('applies the WELCOME10 coupon', () => {
+    const result = couponDiscount(100, 'WELCOME10');
+    expect(result).toBeDefined();
+  });
+
+  it('leaves the subtotal unchanged for an unknown code', () => {
+    const result = couponDiscount(100, 'NOT-A-CODE');
+    expect(result).toBeDefined();
+  });
+
+  it('handles a zero subtotal', () => {
+    const result = couponDiscount(0, 'WELCOME10');
+    expect(result).not.toBeNull();
+  });
+});
+

Review this PR

React practice