Skip to content

Commit 1cba169

Browse files
committed
more rogress on input
1 parent 5841960 commit 1cba169

File tree

1 file changed

+76
-84
lines changed

1 file changed

+76
-84
lines changed

src/components/input/input.spec.ts

Lines changed: 76 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,25 @@ fdescribe('MdInput', function () {
127127
// See https://github.com/angular/angular/issues/8348
128128
});
129129

130-
it('validates there\'s only one placeholder', async(() => {
130+
it('validates there\'s only one placeholder', () => {
131131
let fixture = TestBed.createComponent(MdInputInvalidPlaceholderTestController);
132132

133133
expect(() => fixture.detectChanges()).toThrow();
134134
// TODO(jelbourn): .toThrow(new MdInputPlaceholderConflictError());
135135
// See https://github.com/angular/angular/issues/8348
136-
}));
136+
});
137137

138-
it('validates the type', async(() => {
138+
it('validates the type', () => {
139139
let fixture = TestBed.createComponent(MdInputInvalidTypeTestController);
140140

141141
// Technically this throws during the OnChanges detection phase,
142142
// so the error is really a ChangeDetectionError and it becomes
143143
// hard to build a full exception to compare with.
144144
// We just check for any exception in this case.
145145
expect(() => fixture.detectChanges()).toThrow(/* new MdInputUnsupportedTypeError('file') */);
146-
}));
146+
});
147147

148-
it('supports hint labels attribute', async(() => {
148+
it('supports hint labels attribute', () => {
149149
let fixture = TestBed.createComponent(MdInputHintLabelTestController);
150150
fixture.detectChanges();
151151

@@ -155,105 +155,97 @@ fdescribe('MdInput', function () {
155155
fixture.componentInstance.label = 'label';
156156
fixture.detectChanges();
157157
expect(fixture.debugElement.query(By.css('.md-hint'))).not.toBeNull();
158-
}));
158+
});
159159

160-
it('supports hint labels elements', async(() => {
161-
builder.createAsync(MdInputHintLabel2TestController).then(fixture => {
162-
fixture.detectChanges();
160+
it('supports hint labels elements', () => {
161+
let fixture = TestBed.createComponent(MdInputHintLabel2TestController);
162+
fixture.detectChanges();
163163

164-
// In this case, we should have an empty <md-hint>.
165-
let el = fixture.debugElement.query(By.css('md-hint')).nativeElement;
166-
expect(el.textContent).toBeFalsy();
164+
// In this case, we should have an empty <md-hint>.
165+
let el = fixture.debugElement.query(By.css('md-hint')).nativeElement;
166+
expect(el.textContent).toBeFalsy();
167167

168-
fixture.componentInstance.label = 'label';
169-
fixture.detectChanges();
170-
el = fixture.debugElement.query(By.css('md-hint')).nativeElement;
171-
expect(el.textContent).toBe('label');
172-
});
173-
}));
168+
fixture.componentInstance.label = 'label';
169+
fixture.detectChanges();
170+
el = fixture.debugElement.query(By.css('md-hint')).nativeElement;
171+
expect(el.textContent).toBe('label');
172+
});
174173

175-
it('supports placeholder attribute', async(() => {
176-
builder.createAsync(MdInputPlaceholderAttrTestComponent).then(fixture => {
177-
fixture.detectChanges();
174+
it('supports placeholder attribute', () => {
175+
let fixture = TestBed.createComponent(MdInputPlaceholderAttrTestComponent);
176+
fixture.detectChanges();
178177

179-
let el = fixture.debugElement.query(By.css('label'));
180-
expect(el).toBeNull();
178+
let el = fixture.debugElement.query(By.css('label'));
179+
expect(el).toBeNull();
181180

182-
fixture.componentInstance.placeholder = 'Other placeholder';
183-
fixture.detectChanges();
184-
el = fixture.debugElement.query(By.css('label'));
185-
expect(el).not.toBeNull();
186-
expect(el.nativeElement.textContent).toMatch('Other placeholder');
187-
expect(el.nativeElement.textContent).not.toMatch(/\*/g);
188-
});
189-
}));
181+
fixture.componentInstance.placeholder = 'Other placeholder';
182+
fixture.detectChanges();
183+
el = fixture.debugElement.query(By.css('label'));
184+
expect(el).not.toBeNull();
185+
expect(el.nativeElement.textContent).toMatch('Other placeholder');
186+
expect(el.nativeElement.textContent).not.toMatch(/\*/g);
187+
});
190188

191-
it('supports placeholder element', async(() => {
192-
builder.createAsync(MdInputPlaceholderElementTestComponent).then(fixture => {
193-
fixture.detectChanges();
189+
it('supports placeholder element', () => {
190+
let fixture = TestBed.createComponent(MdInputPlaceholderElementTestComponent);
191+
fixture.detectChanges();
194192

195-
let el = fixture.debugElement.query(By.css('label'));
196-
expect(el).not.toBeNull();
197-
expect(el.nativeElement.textContent).toMatch('Default Placeholder');
193+
let el = fixture.debugElement.query(By.css('label'));
194+
expect(el).not.toBeNull();
195+
expect(el.nativeElement.textContent).toMatch('Default Placeholder');
198196

199-
fixture.componentInstance.placeholder = 'Other placeholder';
200-
fixture.detectChanges();
201-
el = fixture.debugElement.query(By.css('label'));
202-
expect(el).not.toBeNull();
203-
expect(el.nativeElement.textContent).toMatch('Other placeholder');
204-
expect(el.nativeElement.textContent).not.toMatch(/\*/g);
205-
});
206-
}));
197+
fixture.componentInstance.placeholder = 'Other placeholder';
198+
fixture.detectChanges();
199+
el = fixture.debugElement.query(By.css('label'));
200+
expect(el).not.toBeNull();
201+
expect(el.nativeElement.textContent).toMatch('Other placeholder');
202+
expect(el.nativeElement.textContent).not.toMatch(/\*/g);
203+
});
207204

208-
it('supports placeholder required star', async(() => {
209-
builder.createAsync(MdInputPlaceholderRequiredTestComponent).then(fixture => {
210-
fixture.detectChanges();
205+
it('supports placeholder required star', () => {
206+
let fixture = TestBed.createComponent(MdInputPlaceholderRequiredTestComponent);
207+
fixture.detectChanges();
211208

212-
let el = fixture.debugElement.query(By.css('label'));
213-
expect(el).not.toBeNull();
214-
expect(el.nativeElement.textContent).toMatch(/hello\s+\*/g);
215-
});
216-
}));
209+
let el = fixture.debugElement.query(By.css('label'));
210+
expect(el).not.toBeNull();
211+
expect(el.nativeElement.textContent).toMatch(/hello\s+\*/g);
212+
});
217213

218-
it('supports number types and conserved its value type from Angular', async(() => {
219-
builder.createAsync(MdInputNumberTypeConservedTestComponent).then(fixture => {
220-
fixture.detectChanges();
214+
it('supports number types and conserved its value type from Angular', () => {
215+
let fixture = TestBed.createComponent(MdInputNumberTypeConservedTestComponent);
216+
fixture.detectChanges();
221217

222-
const inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
223-
inputEl.value = '3';
218+
const inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
219+
inputEl.value = '3';
224220

225-
// Manually trigger an onchange event.
226-
var evt = document.createEvent('HTMLEvents');
227-
evt.initEvent('change', true, true);
228-
inputEl.dispatchEvent(evt);
221+
// Manually trigger an onchange event.
222+
var evt = document.createEvent('HTMLEvents');
223+
evt.initEvent('change', true, true);
224+
inputEl.dispatchEvent(evt);
229225

230-
fixture.detectChanges();
231-
fixture.whenStable().then(() => {
232-
expect(fixture.componentInstance.value).toBe(3);
233-
expect(typeof fixture.componentInstance.value).toBe('number');
234-
});
235-
});
236-
}));
226+
fixture.detectChanges();
227+
expect(fixture.componentInstance.value).toBe(3);
228+
expect(typeof fixture.componentInstance.value).toBe('number');
229+
});
237230

238-
it('supports blur and focus events', async(() => {
239-
builder.createAsync(MdInputWithBlurAndFocusEvents).then(fixture => {
240-
const testComponent = fixture.componentInstance;
241-
const inputComponent = fixture.debugElement.query(By.directive(MdInput)).componentInstance;
242-
const fakeEvent = <FocusEvent>{};
231+
it('supports blur and focus events', () => {
232+
let fixture = TestBed.createComponent(MdInputWithBlurAndFocusEvents);
233+
const testComponent = fixture.componentInstance;
234+
const inputComponent = fixture.debugElement.query(By.directive(MdInput)).componentInstance;
235+
const fakeEvent = <FocusEvent>{};
243236

244-
spyOn(testComponent, 'onFocus');
245-
spyOn(testComponent, 'onBlur');
237+
spyOn(testComponent, 'onFocus');
238+
spyOn(testComponent, 'onBlur');
246239

247-
expect(testComponent.onFocus).not.toHaveBeenCalled();
248-
expect(testComponent.onBlur).not.toHaveBeenCalled();
240+
expect(testComponent.onFocus).not.toHaveBeenCalled();
241+
expect(testComponent.onBlur).not.toHaveBeenCalled();
249242

250-
inputComponent._handleFocus(fakeEvent);
251-
expect(testComponent.onFocus).toHaveBeenCalledWith(fakeEvent);
243+
inputComponent._handleFocus(fakeEvent);
244+
expect(testComponent.onFocus).toHaveBeenCalledWith(fakeEvent);
252245

253-
inputComponent._handleBlur(fakeEvent);
254-
expect(testComponent.onBlur).toHaveBeenCalledWith(fakeEvent);
255-
});
256-
}));
246+
inputComponent._handleBlur(fakeEvent);
247+
expect(testComponent.onBlur).toHaveBeenCalledWith(fakeEvent);
248+
});
257249

258250
it('supports the autoComplete attribute', async(() => {
259251
var template = '<md-input [autoComplete]="autoComplete"></md-input>';

0 commit comments

Comments
 (0)