Skip to content

Commit d10ce0d

Browse files
committed
test(forms): add test to confirm FormUiControl supports transforming inputs
Issue #65889 reported that FormUiControl does not support transformed inputs. This test asserts that FormValueControl components can legally use type-altering transforms for inputs like the disabled property. Closes #65889
1 parent ebfb19a commit d10ce0d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

packages/forms/signals/test/web/form_field_directive.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,33 @@ describe('field directive', () => {
523523
act(() => component.field.set(component.f.y));
524524
expect(component.customControl().disabled()).toBe(false);
525525
});
526+
527+
it('should allow custom control inputs to have a transform', () => {
528+
@Component({selector: 'custom-control', template: ``})
529+
class CustomControl implements FormValueControl<string> {
530+
readonly value = model('');
531+
readonly disabled = input(false, {transform: booleanAttribute});
532+
}
533+
534+
@Component({
535+
imports: [FormField, CustomControl],
536+
template: `<custom-control [formField]="f" />`,
537+
})
538+
class TestCmp {
539+
readonly disabled = signal(false);
540+
readonly f = form(signal(''), (p) => {
541+
disabled(p, this.disabled);
542+
});
543+
readonly customControl = viewChild.required(CustomControl);
544+
}
545+
546+
const fixture = act(() => TestBed.createComponent(TestCmp));
547+
const component = fixture.componentInstance;
548+
expect(component.customControl().disabled()).toBe(false);
549+
550+
act(() => component.disabled.set(true));
551+
expect(component.customControl().disabled()).toBe(true);
552+
});
526553
});
527554

528555
describe('disabledReasons', () => {

0 commit comments

Comments
 (0)