All jobs / Frontend / web developer / Testing
Frontend / web developer interview question · 1–3 years
A test passes when run alone and fails when the whole file runs, and the failing test changes when you reorder them.
What do you look for?
The strongest answer
Shared state leaking between tests: a module-level variable, a mock never reset, storage or timers left over. Reset in beforeEach or afterEach and build fresh data per test so order cannot matter
Why it works
Right — order dependence means tests share something. Isolation is the rule: each test sets up and tears down its own world.
What a good answer covers
- Order-dependent means shared state.
- Hunt for leftovers between tests.
- Reset mocks, storage and timers.
- Fresh data for every test.
Answers that fall short
- Close, but not the strongest: A mock that is not being reset — I would add a reset call for that one mock
Often the culprit, but check module state, storage and timers too, and fix the pattern rather than one mock. - Weak: The test runner is unreliable at running tests in sequence, so I would re-run until it passes
Runners are deterministic here; a result that depends on order is information, not noise. - Red flag: Mark the failing test as skipped so the pipeline is green, and look at it if there is time
A skipped test protects nothing, and “if there is time” means never.
Who gets asked this
More Testing questions
- A Playwright or Cypress suite fails about one run in five on CI, in different places. The tests are full of…
- After a bad release, management asks you to enforce 90% code coverage on the frontend repository as a merge…
- How do you catch layout breakage before you translate into German and Hebrew?
- What is the difference between a unit test, a component test and an end-to-end test on the frontend, and…
- How do you assert a login button in React Testing Library?
- How do you test a search box that debounces input by 300 ms, in Jest or Vitest, without slowing the suite…