angular/packages/forms/test/ng_control_status_spec.ts
Joey Perrott 9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00

49 lines
1.8 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectionStrategy, Component} from '@angular/core';
import {FormControl, FormsModule, ReactiveFormsModule, Validators} from '../public_api';
import {TestBed} from '@angular/core/testing';
import {provideExperimentalZonelessChangeDetection} from '@angular/core/src/change_detection/scheduling/zoneless_scheduling_impl';
describe('status host binding classes', () => {
beforeEach(() => {
TestBed.configureTestingModule({providers: [provideExperimentalZonelessChangeDetection()]});
});
it('work in OnPush components', async () => {
@Component({
selector: 'test-cmp',
template: `<input type="text" [formControl]="control">`,
standalone: true,
imports: [FormsModule, ReactiveFormsModule],
changeDetection: ChangeDetectionStrategy.OnPush,
})
class App {
control = new FormControl('old value', [Validators.required]);
}
const fixture = TestBed.createComponent(App);
await fixture.whenStable();
expect(fixture.nativeElement.innerHTML).toContain('ng-valid');
expect(fixture.nativeElement.innerHTML).toContain('ng-untouched');
expect(fixture.nativeElement.innerHTML).toContain('ng-pristine');
fixture.componentInstance.control.setValue(null);
await fixture.whenStable();
expect(fixture.nativeElement.innerHTML).toContain('ng-invalid');
fixture.debugElement.query((x) => x.name === 'input').triggerEventHandler('blur');
await fixture.whenStable();
expect(fixture.nativeElement.innerHTML).toContain('ng-touched');
fixture.componentInstance.control.reset();
await fixture.whenStable();
expect(fixture.nativeElement.innerHTML).toContain('ng-untouched');
});
});