🧪Arrange-Act-Assert (AAA)
Also known as AAA Pattern, Arrange Act Assert, AAA Test Pattern
A test in three steps. Set it up, run it, then check the result.
Think of it like
Think of it like a magic trick. You set up the cards, you do the trick, and then you show the card.
Example
Jack's test sets a price of 100, runs addTax and checks the answer is 120. Each step is one line.
Why it matters
Anyone can read a test shaped this way and see what it proves.
Definition
Example code
javascript
test("adds tax to the price", () => {
const price = 100; // Arrange
const total = addTax(price); // Act
expect(total).toBe(120); // Assert
});Common mistake
Key takeaways
- 1Arrange. Set up the inputs.
- 2Act. Run one thing.
- 3Assert. Check the result.