@@ -565,7 +565,11 @@ https://chrisoldwood.blogspot.com/2016/11/tautologies-in-tests.html
565565-->
566566
567567---
568- layout: default
568+ layout: code
569+ h1:
570+ type: semicolon
571+ color: muted
572+ position: end
569573---
570574
571575# Tautological Test
@@ -662,6 +666,58 @@ Assert: (and/or verify) that everything went as expected.
662666There was also "Record-And-Replay" but no one seems to be using that anymore.
663667-->
664668
669+ ---
670+ layout: code
671+ ---
672+
673+ # AAA in Practice
674+
675+ ``` ts {1|2-5|7-8|10-11|all}
676+ test (" calculateTotal_multipleItems_returnsSumOfPrices" , () => {
677+ // Arrange
678+ const cart = new ShoppingCart ()
679+ cart .add ({ name: ' Socks' , price: 9.99 })
680+ cart .add ({ name: ' Shoes' , price: 79.99 })
681+
682+ // Act
683+ const total = cart .calculateTotal ()
684+
685+ // Assert
686+ expect (total ).toBe (89.98 )
687+ })
688+ ```
689+
690+ <div class =" mt-4 text-center text-lg " >
691+ <div v-click.hide =" 1 " class =" text-orange-400 " ><strong >Method_Scenario_Expected</strong > — What are we testing?</div >
692+ <div v-click =" [1,2] " class =" text-emerald-400 " ><strong >Arrange</strong > — Set up the system under test</div >
693+ <div v-click =" [2,3] " class =" text-cyan-400 " ><strong >Act</strong > — Execute the behavior</div >
694+ <div v-click =" [3,4] " class =" text-pink-400 " ><strong >Assert</strong > — Verify the outcome</div >
695+ </div >
696+
697+ ---
698+ layout: default
699+ ---
700+
701+ # Mocking in Practice
702+
703+ ``` ts {1-3|5-9|11-12|14-15|all}
704+ // Arrange: create mock
705+ const emailService = mock <EmailService >()
706+ emailService .send .mockResolvedValue ({ success: true })
707+
708+ // Arrange: inject mock
709+ const orderService = new OrderService ({
710+ emailService ,
711+ // ... other deps
712+ })
713+
714+ // Act
715+ await orderService .placeOrder (order )
716+
717+ // Assert: verify behavior
718+ expect (emailService .send ).toHaveBeenCalledWith (order .customerEmail )
719+ ```
720+
665721---
666722layout: default
667723hide: true
@@ -675,7 +731,6 @@ hide: true
675731- ** Mystery guest** — Hidden dependencies on external data not visible in test
676732- ** Obscure test** — Hard to understand what's being tested
677733- ** Eager test** — Testing too many things at once
678- - ** Sensitive equality** — Asserting entire objects when one field matters
679734
680735</v-clicks >
681736
0 commit comments