mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(slide-toggle): slide-toggle module depends on forms module (#5523)
* Currently the slide-toggle module always imports the `FormsModule` and therefore when treeshaking the `FormsModule` would be always included (even if FormsModule is not used at all)
This commit is contained in:
committed by
mmalerba
parent
173cdddd8f
commit
d716b002ef
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import {NgModule} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser';
|
||||
import {MdSlideToggle} from './slide-toggle';
|
||||
import {
|
||||
@@ -19,7 +18,7 @@ import {
|
||||
} from '../core';
|
||||
|
||||
@NgModule({
|
||||
imports: [FormsModule, MdRippleModule, MdCommonModule, PlatformModule],
|
||||
imports: [MdRippleModule, MdCommonModule, PlatformModule],
|
||||
exports: [MdSlideToggle, MdCommonModule],
|
||||
declarations: [MdSlideToggle],
|
||||
providers: [
|
||||
|
||||
@@ -26,6 +26,53 @@ describe('MdSlideToggle', () => {
|
||||
TestBed.compileComponents();
|
||||
}));
|
||||
|
||||
describe('without form modules', () => {
|
||||
let fixture: ComponentFixture<SlideToggleWithoutForms>;
|
||||
let slideToggleInstance: MdSlideToggle;
|
||||
let labelElement: HTMLLabelElement;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.resetTestingModule();
|
||||
TestBed.configureTestingModule({
|
||||
imports: [MdSlideToggleModule],
|
||||
declarations: [SlideToggleWithoutForms]
|
||||
});
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SlideToggleWithoutForms);
|
||||
fixture.detectChanges();
|
||||
|
||||
const slideToggleDebug = fixture.debugElement.query(By.directive(MdSlideToggle));
|
||||
|
||||
slideToggleInstance = slideToggleDebug.componentInstance;
|
||||
labelElement = fixture.debugElement.query(By.css('label')).nativeElement;
|
||||
});
|
||||
|
||||
it('should update the checked state on click', () => {
|
||||
expect(slideToggleInstance.checked)
|
||||
.toBe(false, 'Expected the slide-toggle not to be checked initially.');
|
||||
|
||||
labelElement.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(slideToggleInstance.checked)
|
||||
.toBe(true, 'Expected the slide-toggle to be checked after click.');
|
||||
});
|
||||
|
||||
it('should update the checked state from binding', () => {
|
||||
expect(slideToggleInstance.checked)
|
||||
.toBe(false, 'Expected the slide-toggle not to be checked initially.');
|
||||
|
||||
fixture.componentInstance.isChecked = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(slideToggleInstance.checked)
|
||||
.toBe(true, 'Expected the slide-toggle to be checked after click.');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('basic behavior', () => {
|
||||
let fixture: ComponentFixture<any>;
|
||||
|
||||
@@ -720,3 +767,10 @@ class SlideToggleFormsTestApp {
|
||||
class SlideToggleWithFormControl {
|
||||
formControl = new FormControl();
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: `<md-slide-toggle [checked]="isChecked"></md-slide-toggle>`
|
||||
})
|
||||
class SlideToggleWithoutForms {
|
||||
isChecked = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user