Question presented to candidate:
"Some of our older specs provide ComponentFixtureAutoDetect and never call detectChanges(); the newer ones never mention it. What does that token do, and how does its behaviour differ between a Zone.js project and a zoneless Angular 22 project?"
What a strong answer should cover:
ComponentFixtureAutoDetectis an injection token read when a fixture is created;truemakes the fixture re-render automatically, like a running app would.- With Zone.js the default is off: you call
detectChanges()after every change. Turned on, change detection runs at the end of each zone turn (events, timers, promises started insideNgZone), but a direct write from the test body is still missed. - Zoneless (the Angular 22 default), auto detect is on by default; signals, template events and
setInput()schedule a render, andawait fixture.whenStable()waits for it. - In zoneless mode you cannot turn it off:
fixture.autoDetectChanges(false)throws; providing the token asfalseleaves the fixture unable to render. fixture.autoDetectChanges()is the per-fixture equivalent of providing the token as true.- Auto detect does not remove the need to await: rendering is still asynchronous.
Clarifying questions expected:
- "Does the project still load Zone.js, or is it zoneless?"
- "Are the components using signals, or plain fields?"
Code / implementation expected: Yes β a spec that shows the default zoneless behaviour, and one Zone-based spec with the token on and off.