Great question!
✅ Short Answer:
No, you do not use JSDoc to document Jest's describe, it, or test functions. Those are behavior-driven development (BDD) constructs for writing tests, not for documenting code with JSDoc.
📌 Why?
JSDoc is meant for documenting your actual JavaScript source code — the functions, classes, methods, parameters, and return values that constitute your application logic.
Jest, on the other hand, uses describe, it, and test to write tests to verify that your code works as intended. These don’t need JSDoc comments — you use clear naming and structure to ensure test readability.
✅ What Should You Document with JSDoc?
You should document things like this:
✅ A basic JSDoc-documented function example
/**
* Adds two numbers together.
*
* @function add
* @param {number} a - First number to add.
* @param {number} b - Second number to add.
* @returns {number} Sum of the two numbers.
*
* @example
* const result = add(2, 3);
* console.log(result); // 5
*/
function add(a, b) {
return a + b;
}
✍️ Example Test File (No JSDoc needed for tests)
const add = require('./add');
describe('add', () => {
it('should correctly add two positive numbers', () => {
expect(add(2, 3)).toBe(5);
});
it('should correctly add negative numbers', () => {
expect(add(-2, -3)).toBe(-5);
});
});
🧠 Summary
| Item | Needs JSDoc? | Why? |
|---|
| Functions | ✅ Yes | To explain usage, inputs, and outputs |
| Classes | ✅ Yes | To describe object structure |
| Jest tests | ❌ No | Describe using natural language in describe() and it() |
Would you like an example that includes both a documented function and its Jest test file together?