function applyDiscount(user, total) { if (user.type === 'VIP') return total * 0.8; return total; }
Last Tuesday was the breaking point. A simple pull request to update a discount function caused a catastrophic cascade. The login failed. The cart emptied. The CEO’s test account showed a total price of . The company had to pay customers to buy things.
He still watched Code With Mosh videos on the train, moving on to Mastering TypeScript and Design Patterns . But he never forgot that first green checkmark.
Mosh started simple.
test('apply 20% discount to VIP users', () => { const user = { type: 'VIP' }; const total = 100; const result = applyDiscount(user, total); expect(result).toBe(80); }); He ran it. The function didn't exist yet.
He wrote the simplest possible code to turn it green:
Because Leo finally understood: writing tests wasn't about proving his code worked today. It was about having the courage to change it tomorrow.
expect(result.method).toBe('creditCard'); });
function applyDiscount(user, total) { if (user.type === 'VIP') return total * 0.8; return total; }
Last Tuesday was the breaking point. A simple pull request to update a discount function caused a catastrophic cascade. The login failed. The cart emptied. The CEO’s test account showed a total price of . The company had to pay customers to buy things.
He still watched Code With Mosh videos on the train, moving on to Mastering TypeScript and Design Patterns . But he never forgot that first green checkmark.
Mosh started simple.
test('apply 20% discount to VIP users', () => { const user = { type: 'VIP' }; const total = 100; const result = applyDiscount(user, total); expect(result).toBe(80); }); He ran it. The function didn't exist yet.
He wrote the simplest possible code to turn it green:
Because Leo finally understood: writing tests wasn't about proving his code worked today. It was about having the courage to change it tomorrow.
expect(result.method).toBe('creditCard'); });