Parameterized Test
Question
What is a parameterized test?
Hint
Parameterized tests reduce duplication for similar test cases.
Explanation
A parameterized test (table-driven test) runs the same test logic with multiple input/expected pairs, reducing duplication. In Jest: test.each([[1, 1, 2], [2, 3, 5], [0, 0, 0]])("adds %i + %i = %i", (a, b, expected) => { expect(add(a, b)).toBe(expected); }). Benefits: 1) Less code — one test definition covers many cases. 2) Easy to add cases — just add to the data array. 3) Clear coverage — visible which cases are tested. 4) Consistent logic — all cases use the same assertions. Use for functions with many input combinations (math, parsing, validation). Avoid for cases that need different setup or assertions.
Related Resources
Related Lessons
- Parameterized Tests
Learn parameterized.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.