Mistake: Multiple Assertions
Find the Mistake Medium
Question
What is wrong with this test?
Code
test('everything works', () => {
expect(add(1, 1)).toBe(2);
expect(subtract(5, 3)).toBe(2);
expect(multiply(2, 3)).toBe(6);
expect(divide(10, 2)).toBe(5);
});
Hint
One test should verify one behavior.
Explanation
The mistake is testing multiple unrelated functions in one test. If the first assertion fails, the remaining assertions never run, so you don't know if they pass or fail. The fix: split into separate tests — one for each function. This gives clearer feedback when something breaks.
Related Resources
Related Lessons
- Test Best Practices
Writing maintainable tests.
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.