test(forms): migrate integration tests to zoneless scheduling

Use whenStable instead of manual change detection so integration tests exercise scheduled rendering. Await asynchronous callbacks and remove redundant timer waits to keep assertions within the test lifecycle.

(cherry picked from commit 8afd85c6d7)
This commit is contained in:
Jaime Burgos
2026-09-09 09:24:37 -05:00
committed by Kristiyan Kostadinov
parent cbb8702143
commit 5dabf81bdf
3 changed files with 543 additions and 722 deletions
@@ -1758,21 +1758,27 @@ describe('reactive forms integration tests', () => {
it('should work with single fields and async validators', async () => {
const fixture = initTest(FormControlComp);
const control = new FormControl('', null!, uniqLoginAsyncValidator('good'));
// Delay validation so the scheduled renders can observe the pending state.
const control = new FormControl('', null!, uniqLoginAsyncValidator('good', 100));
fixture.debugElement.componentInstance.control = control;
fixture.detectChanges();
await fixture.whenStable();
const input = fixture.debugElement.query(By.css('input')).nativeElement;
expect(sortedClassList(input)).toEqual(['ng-pending', 'ng-pristine', 'ng-untouched']);
dispatchEvent(input, 'blur');
fixture.detectChanges();
await fixture.whenStable();
expect(sortedClassList(input)).toEqual(['ng-pending', 'ng-pristine', 'ng-touched']);
input.value = 'good';
dispatchEvent(input, 'input');
await timeout();
fixture.detectChanges();
await fixture.whenStable();
expect(sortedClassList(input)).toEqual(['ng-dirty', 'ng-pending', 'ng-touched']);
// Wait for the validator's 100 ms delay, which keeps it pending during rendering.
// whenStable() doesn't wait for this timer; useAutoTick advances the mock clock.
await timeout(100);
await fixture.whenStable();
expect(sortedClassList(input)).toEqual(['ng-dirty', 'ng-touched', 'ng-valid']);
});
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff