Lesson 9 +15 XP

Generating Unit Tests & Code Documentation

Writing comprehensive unit tests and JSDoc/Docstring documentation is essential, but often tedious. AI is exceptionally good at both!

Generating Comprehensive Unit Tests

Ask the AI to cover edge cases, null checks, and boundary conditions:


markdown
Act as a QA Automation Engineer. Write a suite of unit tests for the `calculateDiscount(price, userLevel)` function using Jest.
- **Make sure to include test cases for**: 1. Standard valid discount calculation.

2. Edge case: 0% discount and 100% discount.

3. Invalid inputs: negative price or invalid user level (should throw error).

Generating Clean JSDoc / Docstrings

"Generate JSDoc comments for this function including @param types, @returns type, a 1-line summary, and an example invocation."