Skip to content

Commit e769cda

Browse files
authored
chore(slide-toggle): remove TestComponentBuilder (#1014)
1 parent 9d51deb commit e769cda

File tree

1 file changed

+22
-75
lines changed

1 file changed

+22
-75
lines changed

src/components/slide-toggle/slide-toggle.spec.ts

Lines changed: 22 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
import {
2-
inject,
3-
async,
4-
TestComponentBuilder,
5-
ComponentFixture,
6-
TestBed,
7-
} from '@angular/core/testing';
1+
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
82
import {By} from '@angular/platform-browser';
93
import {Component} from '@angular/core';
104
import {MdSlideToggle, MdSlideToggleChange, MdSlideToggleModule} from './slide-toggle';
115
import {FormsModule, NgControl} from '@angular/forms';
126

137
describe('MdSlideToggle', () => {
14-
let builder: TestComponentBuilder;
158

169
beforeEach(async(() => {
1710
TestBed.configureTestingModule({
@@ -22,12 +15,7 @@ describe('MdSlideToggle', () => {
2215
TestBed.compileComponents();
2316
}));
2417

25-
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
26-
builder = tcb;
27-
}));
28-
2918
describe('basic behavior', () => {
30-
3119
let fixture: ComponentFixture<any>;
3220

3321
let testComponent: SlideToggleTestApp;
@@ -37,28 +25,27 @@ describe('MdSlideToggle', () => {
3725
let labelElement: HTMLLabelElement;
3826
let inputElement: HTMLInputElement;
3927

28+
// This initialization is async() because it needs to wait for ngModel to set the initial value.
4029
beforeEach(async(() => {
41-
builder.createAsync(SlideToggleTestApp).then(f => {
42-
fixture = f;
30+
fixture = TestBed.createComponent(SlideToggleTestApp);
4331

44-
testComponent = fixture.debugElement.componentInstance;
32+
testComponent = fixture.debugElement.componentInstance;
4533

46-
// Enable jasmine spies on event functions, which may trigger at initialization
47-
// of the slide-toggle component.
48-
spyOn(fixture.debugElement.componentInstance, 'onSlideChange').and.callThrough();
49-
spyOn(fixture.debugElement.componentInstance, 'onSlideClick').and.callThrough();
34+
// Enable jasmine spies on event functions, which may trigger at initialization
35+
// of the slide-toggle component.
36+
spyOn(fixture.debugElement.componentInstance, 'onSlideChange').and.callThrough();
37+
spyOn(fixture.debugElement.componentInstance, 'onSlideClick').and.callThrough();
5038

51-
// Initialize the slide-toggle component, by triggering the first change detection cycle.
52-
fixture.detectChanges();
39+
// Initialize the slide-toggle component, by triggering the first change detection cycle.
40+
fixture.detectChanges();
5341

54-
let slideToggleDebug = fixture.debugElement.query(By.css('md-slide-toggle'));
42+
let slideToggleDebug = fixture.debugElement.query(By.css('md-slide-toggle'));
5543

56-
slideToggle = slideToggleDebug.componentInstance;
57-
slideToggleElement = slideToggleDebug.nativeElement;
58-
slideToggleControl = slideToggleDebug.injector.get(NgControl);
59-
inputElement = fixture.debugElement.query(By.css('input')).nativeElement;
60-
labelElement = fixture.debugElement.query(By.css('label')).nativeElement;
61-
});
44+
slideToggle = slideToggleDebug.componentInstance;
45+
slideToggleElement = slideToggleDebug.nativeElement;
46+
slideToggleControl = slideToggleDebug.injector.get(NgControl);
47+
inputElement = fixture.debugElement.query(By.css('input')).nativeElement;
48+
labelElement = fixture.debugElement.query(By.css('label')).nativeElement;
6249
}));
6350

6451
// TODO(kara); update when core/testing adds fix
@@ -348,53 +335,14 @@ describe('MdSlideToggle', () => {
348335
});
349336

350337
describe('custom template', () => {
351-
352-
let testComponent: SlideToggleTestApp;
353-
let slideToggle: MdSlideToggle;
354-
let slideToggleElement: HTMLElement;
355-
let labelElement: HTMLLabelElement;
356-
let inputElement: HTMLInputElement;
357-
358338
it('should not trigger the change event on initialization', async(() => {
359-
builder
360-
.overrideTemplate(SlideToggleTestApp, `
361-
<md-slide-toggle checked="true" (change)="onSlideChange($event)"></md-slide-toggle>
362-
`)
363-
.createAsync(SlideToggleTestApp)
364-
.then(fixture => {
365-
// Initialize the variables for our test.
366-
initializeTest(fixture);
367-
368-
// Enable jasmine spies on event functions, which may trigger at initialization
369-
// of the slide-toggle component.
370-
spyOn(fixture.debugElement.componentInstance, 'onSlideChange').and.callThrough();
371-
372-
fixture.detectChanges();
373-
374-
fixture.whenStable().then(() => {
375-
expect(testComponent.onSlideChange).not.toHaveBeenCalled();
376-
});
377-
});
378-
}));
379-
380-
/**
381-
* Initializes the suites variables, to allow developers to easily access the several variables
382-
* without loading / querying them always again.
383-
* @param fixture Custom fixture, which contains the slide-toggle component.
384-
*/
385-
function initializeTest(fixture: ComponentFixture<any>) {
386-
testComponent = fixture.debugElement.componentInstance;
387-
388-
// Initialize the slide-toggle component, by triggering the first change detection cycle.
339+
let fixture = TestBed.createComponent(SlideToggleTestApp);
340+
fixture.componentInstance.slideModel = true;
341+
fixture.componentInstance.slideChecked = true;
389342
fixture.detectChanges();
390343

391-
let slideToggleDebug = fixture.debugElement.query(By.css('md-slide-toggle'));
392-
393-
slideToggle = slideToggleDebug.componentInstance;
394-
slideToggleElement = slideToggleDebug.nativeElement;
395-
inputElement = fixture.debugElement.query(By.css('input')).nativeElement;
396-
labelElement = fixture.debugElement.query(By.css('label')).nativeElement;
397-
}
344+
expect(fixture.componentInstance.lastEvent).toBeFalsy();
345+
}));
398346
});
399347

400348
});
@@ -419,8 +367,7 @@ function dispatchFocusChangeEvent(eventName: string, element: HTMLElement): void
419367
(change)="onSlideChange($event)"
420368
(click)="onSlideClick($event)">
421369
<span>Test Slide Toggle</span>
422-
</md-slide-toggle>
423-
`,
370+
</md-slide-toggle>`,
424371
})
425372
class SlideToggleTestApp {
426373
isDisabled: boolean = false;

0 commit comments

Comments
 (0)