@@ -24,7 +24,7 @@ describe('MdAutocomplete', () => {
24
24
imports : [
25
25
MdAutocompleteModule . forRoot ( ) , MdInputModule . forRoot ( ) , ReactiveFormsModule
26
26
] ,
27
- declarations : [ SimpleAutocomplete ] ,
27
+ declarations : [ SimpleAutocomplete , AutocompleteWithoutForms ] ,
28
28
providers : [
29
29
{ provide : OverlayContainer , useFactory : ( ) => {
30
30
overlayContainerElement = document . createElement ( 'div' ) ;
@@ -790,6 +790,27 @@ describe('MdAutocomplete', () => {
790
790
791
791
} ) ;
792
792
793
+ describe ( 'misc' , ( ) => {
794
+
795
+ it ( 'should allow basic use without any forms directives' , ( ) => {
796
+ expect ( ( ) => {
797
+ const fixture = TestBed . createComponent ( AutocompleteWithoutForms ) ;
798
+ fixture . detectChanges ( ) ;
799
+
800
+ const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
801
+ input . value = 'd' ;
802
+ dispatchEvent ( 'input' , input ) ;
803
+ fixture . detectChanges ( ) ;
804
+
805
+ const options =
806
+ overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
807
+ expect ( options . length ) . toBe ( 1 ) ;
808
+
809
+ } ) . not . toThrowError ( ) ;
810
+ } ) ;
811
+
812
+ } ) ;
813
+
793
814
} ) ;
794
815
795
816
@Component ( {
@@ -849,6 +870,33 @@ class SimpleAutocomplete implements OnDestroy {
849
870
}
850
871
851
872
873
+ @Component ( {
874
+ template : `
875
+ <md-input-container>
876
+ <input mdInput placeholder="State" [mdAutocomplete]="auto"
877
+ (input)="onInput($event.target?.value)">
878
+ </md-input-container>
879
+
880
+ <md-autocomplete #auto="mdAutocomplete">
881
+ <md-option *ngFor="let state of filteredStates" [value]="state">
882
+ <span> {{ state }} </span>
883
+ </md-option>
884
+ </md-autocomplete>
885
+ `
886
+ } )
887
+ class AutocompleteWithoutForms {
888
+ filteredStates : any [ ] ;
889
+ states = [ 'Alabama' , 'California' , 'Florida' ] ;
890
+
891
+ constructor ( ) {
892
+ this . filteredStates = this . states . slice ( ) ;
893
+ }
894
+
895
+ onInput ( value : any ) {
896
+ this . filteredStates = this . states . filter ( s => new RegExp ( value , 'gi' ) . test ( s ) ) ;
897
+ }
898
+
899
+ }
852
900
853
901
/**
854
902
* TODO: Move this to core testing utility until Angular has event faking
0 commit comments