📖 Step 7: Testing & Quality#187 / 350

Unit Test

Unit Test

📖One-line summary

A test that checks a single function or component in isolation.

💡Easy explanation

Testing a single function or component in isolation to make sure it works correctly. Like checking each LEGO block before assembling them — catch problems early.

Example

Test a single function in isolation

describe("add function")

add(2, 3)5
add(-1, 1)0
add(0, 0)0

Vibe coding prompt examples

>_

Write unit tests with Jest for the cart total calculation function. Include discount, quantity change, and empty cart cases.

>_

Write unit tests for a React component with Testing Library. Test button click, input, and conditional rendering.

Try these prompts in your AI coding assistant!