@@ -20,7 +20,7 @@ import {
2020 MdAutocomplete ,
2121 MdAutocompleteModule ,
2222 MdAutocompleteTrigger ,
23- MdAutocompleteSelect ,
23+ MdAutocompleteSelectedEvent ,
2424} from './index' ;
2525import { MdInputModule } from '../input/index' ;
2626import { Subscription } from 'rxjs/Subscription' ;
@@ -1466,7 +1466,7 @@ describe('MdAutocomplete', () => {
14661466 } ) ;
14671467 } ) ) ;
14681468
1469- it ( 'should call emit an event when an option is selected' , fakeAsync ( ( ) => {
1469+ it ( 'should emit an event when an option is selected' , fakeAsync ( ( ) => {
14701470 let fixture = TestBed . createComponent ( AutocompleteWithSelectEvent ) ;
14711471
14721472 fixture . detectChanges ( ) ;
@@ -1475,19 +1475,45 @@ describe('MdAutocomplete', () => {
14751475 fixture . detectChanges ( ) ;
14761476
14771477 let options = overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
1478- let spy = fixture . componentInstance . select ;
1478+ let spy = fixture . componentInstance . optionSelected ;
14791479
14801480 options [ 1 ] . click ( ) ;
14811481 tick ( ) ;
14821482 fixture . detectChanges ( ) ;
14831483
14841484 expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
14851485
1486- let event = spy . calls . mostRecent ( ) . args [ 0 ] as MdAutocompleteSelect ;
1486+ let event = spy . calls . mostRecent ( ) . args [ 0 ] as MdAutocompleteSelectedEvent ;
14871487
14881488 expect ( event . source ) . toBe ( fixture . componentInstance . autocomplete ) ;
14891489 expect ( event . option . value ) . toBe ( 'Washington' ) ;
14901490 } ) ) ;
1491+
1492+ it ( 'should emit an event when a newly-added option is selected' , fakeAsync ( ( ) => {
1493+ let fixture = TestBed . createComponent ( AutocompleteWithSelectEvent ) ;
1494+
1495+ fixture . detectChanges ( ) ;
1496+ fixture . componentInstance . trigger . openPanel ( ) ;
1497+ tick ( ) ;
1498+ fixture . detectChanges ( ) ;
1499+
1500+ fixture . componentInstance . states . push ( 'Puerto Rico' ) ;
1501+ fixture . detectChanges ( ) ;
1502+
1503+ let options = overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
1504+ let spy = fixture . componentInstance . optionSelected ;
1505+
1506+ options [ 3 ] . click ( ) ;
1507+ tick ( ) ;
1508+ fixture . detectChanges ( ) ;
1509+
1510+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
1511+
1512+ let event = spy . calls . mostRecent ( ) . args [ 0 ] as MdAutocompleteSelectedEvent ;
1513+
1514+ expect ( event . source ) . toBe ( fixture . componentInstance . autocomplete ) ;
1515+ expect ( event . option . value ) . toBe ( 'Puerto Rico' ) ;
1516+ } ) ) ;
14911517} ) ;
14921518
14931519@Component ( {
@@ -1738,7 +1764,7 @@ class AutocompleteWithFormsAndNonfloatingPlaceholder {
17381764 <input mdInput placeholder="State" [mdAutocomplete]="auto" [(ngModel)]="selectedState">
17391765 </md-input-container>
17401766
1741- <md-autocomplete #auto="mdAutocomplete" (select )="select ($event)">
1767+ <md-autocomplete #auto="mdAutocomplete" (optionSelected )="optionSelected ($event)">
17421768 <md-option *ngFor="let state of states" [value]="state">
17431769 <span>{{ state }}</span>
17441770 </md-option>
@@ -1748,7 +1774,7 @@ class AutocompleteWithFormsAndNonfloatingPlaceholder {
17481774class AutocompleteWithSelectEvent {
17491775 selectedState : string ;
17501776 states = [ 'New York' , 'Washington' , 'Oregon' ] ;
1751- select = jasmine . createSpy ( 'select callback' ) ;
1777+ optionSelected = jasmine . createSpy ( 'optionSelected callback' ) ;
17521778
17531779 @ViewChild ( MdAutocompleteTrigger ) trigger : MdAutocompleteTrigger ;
17541780 @ViewChild ( MdAutocomplete ) autocomplete : MdAutocomplete ;
0 commit comments