🧪Unit Test
Also known as Unit Testing, Unit Tests
A test that checks one small piece of code, like a function, by itself.
Think of it like
Think of it like a box of bricks. You check each brick before you build.
Example
Emma's function adds VAT to a price. Her unit test checks that 100 becomes 120 at a 20% rate, in 2 milliseconds.
Why it matters
They are fast and point at the exact function that broke. That makes them cheap to run on every save.
Definition
Example code
javascript
test('adds 2 + 3', () => {
expect(2 + 3).toBe(5);
});Common mistake
Key takeaways
- 1One small piece. Usually one function.
- 2On its own. No network or database.
- 3Very fast. Milliseconds each.