Skip to content

Commit 59f6ef6

Browse files
SkyZeroZxalxhub
authored andcommitted
refactor(forms): modernize signal forms tests to rely on whenStable
Rely on zoneless test scheduling instead of manually triggering change detection. Keep Signals Forms tests aligned with the async-first testing pattern.
1 parent 21eed5f commit 59f6ef6

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎packages/forms/signals/test/node/field_node.spec.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,15 +1393,15 @@ describe('FieldNode', () => {
13931393

13941394
const fixture = TestBed.createComponent(TestCmp);
13951395
const cmp = fixture.componentInstance;
1396-
fixture.detectChanges();
1396+
await fixture.whenStable();
13971397

13981398
expect(cmp.f().errorSummary()).toEqual([
13991399
jasmine.objectContaining({kind: 'error-b'}),
14001400
jasmine.objectContaining({kind: 'error-a'}),
14011401
]);
14021402
});
14031403

1404-
it('should sort bound errors before unbound errors', () => {
1404+
it('should sort bound errors before unbound errors', async () => {
14051405
@Component({
14061406
template: ` <input [formField]="f.a" /> `,
14071407
imports: [FormField],
@@ -1415,15 +1415,15 @@ describe('FieldNode', () => {
14151415

14161416
const fixture = TestBed.createComponent(TestCmp);
14171417
const cmp = fixture.componentInstance;
1418-
fixture.detectChanges();
1418+
await fixture.whenStable();
14191419

14201420
expect(cmp.f().errorSummary()).toEqual([
14211421
jasmine.objectContaining({kind: 'error-a'}),
14221422
jasmine.objectContaining({kind: 'error-b'}),
14231423
]);
14241424
});
14251425

1426-
it('should sort errors from nested fields by DOM position', () => {
1426+
it('should sort errors from nested fields by DOM position', async () => {
14271427
@Component({
14281428
template: `
14291429
<input [formField]="f.group.child" />
@@ -1440,7 +1440,7 @@ describe('FieldNode', () => {
14401440

14411441
const fixture = TestBed.createComponent(TestCmp);
14421442
const cmp = fixture.componentInstance;
1443-
fixture.detectChanges();
1443+
await fixture.whenStable();
14441444

14451445
expect(cmp.f().errorSummary()).toEqual([
14461446
jasmine.objectContaining({kind: 'child'}),

‎packages/forms/signals/test/web/debounce_async_validation_bug.spec.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ describe('debounced inside validateAsync bug', () => {
4747
}
4848

4949
const fixture = TestBed.createComponent(DebounceBug);
50-
fixture.detectChanges();
5150
await fixture.whenStable();
5251

5352
// In a "zoneless and async-first" testing environment, just need to change something and wait

‎packages/forms/signals/test/web/interop.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ describe('ControlValueAccessor', () => {
469469
expect(fixture.componentInstance.f().value()).toBe('typing');
470470
});
471471

472-
it('should not throw if the ControlValueAccessor implementation uses signals', () => {
472+
it('should not throw if the ControlValueAccessor implementation uses signals', async () => {
473473
@Component({
474474
selector: 'signal-custom-control',
475475
template: `<input [value]="value()" [disabled]="disabled()" />`,
@@ -521,7 +521,7 @@ describe('ControlValueAccessor', () => {
521521
}
522522

523523
const fixture = TestBed.createComponent(App);
524-
expect(() => fixture.detectChanges()).not.toThrowError(/NG0600/);
524+
await expectAsync(fixture.whenStable()).not.toBeRejectedWithError(/NG0600/);
525525

526526
expect(() => fixture.componentInstance.disabled.set(true)).not.toThrowError(/NG0600/);
527527
});

0 commit comments

Comments
 (0)