Question presented to candidate:
"In a TestBed spec you create a component and the DOM is empty. What does fixture.detectChanges() actually do, when do you need to call it, and is it still the right tool in a zoneless Angular 22 project?"
What a strong answer should cover:
TestBed.createComponent()builds the component and its host element but does not render bindings; change detection has to run first.fixture.detectChanges()runs one synchronous change detection pass for the fixture and then, in dev mode, acheckNoChanges()pass that throwsNG0100if a value changed after it was checked.- Under OnPush (the v22 default),
detectChanges()only refreshes views that are dirty: signals, template events,setInput()andmarkForCheck()mark them; a plain field assignment does not. - In a zoneless TestBed (the CLI default), the fixture already auto-detects; the generated spec uses
await fixture.whenStable()to let Angular render the way the app would. - When to prefer which:
detectChanges()for a precise, synchronous step (and with fake timers);whenStable()for realistic, async flows. - Seeing
NG0100in a zoneless test usually means state was changed without notifying Angular.
Clarifying questions expected:
- "Is the project zoneless, or does it still load Zone.js?"
- "Are the components OnPush (the v22 default) or Eager?"
Code / implementation expected: Yes β a spec showing the first render, a signal update, the OnPush plain-field trap and an NG0100.