|
1 | 1 | import {async, TestBed, inject} from '@angular/core/testing';
|
2 | 2 | import {Component} from '@angular/core';
|
3 |
| -import {FormsModule, ReactiveFormsModule} from '@angular/forms'; |
| 3 | +import {FormsModule, ReactiveFormsModule, FormControl} from '@angular/forms'; |
4 | 4 | import {By} from '@angular/platform-browser';
|
5 | 5 | import {MdInputModule} from './input';
|
6 |
| -import {MdInputContainer} from './input-container'; |
| 6 | +import {MdInputContainer, MdInputDirective} from './input-container'; |
7 | 7 | import {Platform} from '../core/platform/platform';
|
8 | 8 | import {PlatformModule} from '../core/platform/index';
|
9 | 9 | import {
|
@@ -41,7 +41,8 @@ describe('MdInputContainer', function () {
|
41 | 41 | MdInputContainerZeroTestController,
|
42 | 42 | MdTextareaWithBindings,
|
43 | 43 | MdInputContainerWithDisabled,
|
44 |
| - MdInputContainerMissingMdInputTestController |
| 44 | + MdInputContainerMissingMdInputTestController, |
| 45 | + MdInputContainerWithFormControl |
45 | 46 | ],
|
46 | 47 | });
|
47 | 48 |
|
@@ -293,6 +294,21 @@ describe('MdInputContainer', function () {
|
293 | 294 | const textarea: HTMLTextAreaElement = fixture.nativeElement.querySelector('textarea');
|
294 | 295 | expect(textarea).not.toBeNull();
|
295 | 296 | });
|
| 297 | + |
| 298 | + it('should update the value when using FormControl.setValue', () => { |
| 299 | + let fixture = TestBed.createComponent(MdInputContainerWithFormControl); |
| 300 | + fixture.detectChanges(); |
| 301 | + |
| 302 | + let input = fixture.debugElement.query(By.directive(MdInputDirective)) |
| 303 | + .injector.get(MdInputDirective) as MdInputDirective; |
| 304 | + |
| 305 | + expect(input.value).toBeFalsy(); |
| 306 | + |
| 307 | + fixture.componentInstance.formControl.setValue('something'); |
| 308 | + |
| 309 | + expect(input.value).toBe('something'); |
| 310 | + }); |
| 311 | + |
296 | 312 | });
|
297 | 313 |
|
298 | 314 | @Component({
|
@@ -446,6 +462,13 @@ class MdTextareaWithBindings {
|
446 | 462 | })
|
447 | 463 | class MdInputContainerMissingMdInputTestController {}
|
448 | 464 |
|
| 465 | +@Component({ |
| 466 | + template: `<md-input-container><input md-input [formControl]="formControl"></md-input-container>` |
| 467 | +}) |
| 468 | +class MdInputContainerWithFormControl { |
| 469 | + formControl = new FormControl(); |
| 470 | +} |
| 471 | + |
449 | 472 | /**
|
450 | 473 | * Gets a RegExp used to detect an angular wrapped error message.
|
451 | 474 | * See https://github.com/angular/angular/issues/8348
|
|
0 commit comments