Testing & QA Bug Hunt Hard +35 XP
Test Pollution
Tests pass individually but fail when run together.
Testing & QAFind the bug
1
let data = [];2
test("adds item", () => { data.push(1); expect(data).toHaveLength(1); });3
test("empty check", () => { expect(data).toHaveLength(0); }); The bug is on line 1
Select the correct fix
Show answer and explanation
Answer: Both A and B fix it
Shared mutable state between tests causes pollution. Use beforeEach to reset, or declare state inside each test.
Hint: Tests should not share mutable state.
What this challenge tests
Bug Hunt in Testing & QA: test-isolation, state.