mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
test(slide-toggle): verify that NgControl stays pristine if initial value is set (#4970)
* If a developer sets an initial value for the slide-toggle the NgControl of the slide-toggle can turn dirty. The slide-toggle should only turn dirty if the value changed after initialization. This adds a test to confirm that this is not the case.
This commit is contained in:
committed by
tinayuangao
parent
a882546deb
commit
9b45681fcd
@@ -631,6 +631,21 @@ describe('MdSlideToggle with forms', () => {
|
||||
expect(slideToggle.checked)
|
||||
.toBe(false, 'Expected slide-toggle to be no longer checked after label click.');
|
||||
}));
|
||||
|
||||
it('should be pristine if initial value is set from NgModel', fakeAsync(() => {
|
||||
fixture = TestBed.createComponent(SlideToggleWithModel);
|
||||
|
||||
fixture.componentInstance.modelValue = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
const debugElement = fixture.debugElement.query(By.directive(MdSlideToggle));
|
||||
const modelInstance = debugElement.injector.get<NgModel>(NgModel);
|
||||
|
||||
// Flush the microtasks because the forms module updates the model state asynchronously.
|
||||
flushMicrotasks();
|
||||
|
||||
expect(modelInstance.pristine).toBe(true);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('with a FormControl', () => {
|
||||
|
||||
Reference in New Issue
Block a user