test.each
Predict Output Medium
Question
What does this test code print?
Code
test.each([[1, 1, 2], [2, 3, 5]])
("add %i + %i = %i", (a, b, exp) => {
expect(a + b).toBe(exp);
});
// Result?
Hint
Both cases: 1+1=2 and 2+3=5 are correct.
Explanation
test.each runs the test for each data row. [1, 1, 2]: 1+1=2 passes. [2, 3, 5]: 2+3=5 passes. Both parameterized cases pass.
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.