Skip to content

-code With Mosh- Mastering Javascript Unit Testing Here

"So," she said. "Did Mosh save you?"

"Watch this."

Leo decided to rewrite the cursed discount function. He opened a new file: discount.test.js . -Code With Mosh- Mastering JavaScript Unit Testing

She started laughing. "Best thirty dollars this company ever spent." Six months later, Leo wasn't a firefighter anymore. He was the team's testing evangelist. New hires came to him with shaky pull requests, and he'd say the same thing Mosh said to him: "So," she said

test('should use credit card if PayPal fails', async () => { // Mock the failing PayPal service const mockPayPal = jest.fn().mockRejectedValue(new Error('Timeout')); const result = await processPayment(mockPayPal, 'creditCard'); async () =&gt

Leo plugged in his laptop and opened the test suite.

He wrote his first failing test: