Performance: Testing forms and user interactions
MEDIUM IMPACT
This affects how quickly and smoothly user inputs are processed and how responsive the form feels during interaction.
it('good test', async () => { const input = fixture.nativeElement.querySelector('input'); input.value = 'test'; input.dispatchEvent(new Event('input')); fixture.detectChanges(); await fixture.whenStable(); expect(component.form.value).toEqual({name: 'test'}); });
it('bad test', () => { const input = fixture.nativeElement.querySelector('input'); input.value = 'test'; input.dispatchEvent(new Event('input')); fixture.detectChanges(); // No async wait for debounce or async validators expect(component.form.value).toEqual({name: 'test'}); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous detectChanges without async wait | Multiple DOM updates | Multiple reflows per input | High paint cost due to forced sync updates | [X] Bad |
| Async test with fixture.whenStable() | Minimal DOM updates batched | Single reflow after stable state | Lower paint cost with smooth updates | [OK] Good |