mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
test(forms): field directive marks field as touched on 'blur' events (#64485)
This was implemented but missing a test case. PR Close #64485
This commit is contained in:
committed by
Jessica Janiuk
parent
ecb2507c8b
commit
e9740662c3
@@ -994,6 +994,28 @@ describe('field directive', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it(`should mark field as touched on native control 'blur' event`, () => {
|
||||
@Component({
|
||||
imports: [Field],
|
||||
template: `<input [field]="f">`,
|
||||
})
|
||||
class TestCmp {
|
||||
f = form(signal(''));
|
||||
}
|
||||
|
||||
const fixture = act(() => TestBed.createComponent(TestCmp));
|
||||
const input = fixture.nativeElement.firstChild as HTMLInputElement;
|
||||
const field = fixture.componentInstance.f;
|
||||
|
||||
expect(field().touched()).toBe(false);
|
||||
|
||||
act(() => {
|
||||
input.dispatchEvent(new Event('blur'));
|
||||
});
|
||||
|
||||
expect(field().touched()).toBe(true);
|
||||
});
|
||||
|
||||
it('should synchronize with custom control touched status', () => {
|
||||
@Component({
|
||||
selector: 'my-input',
|
||||
|
||||
Reference in New Issue
Block a user