@@ -756,6 +756,39 @@ export function main() {
756756 // selection start has not changed because we did not reset the value
757757 expect ( input . selectionStart ) . toEqual ( 1 ) ;
758758 } ) ) ) ;
759+
760+ it ( "should update the view when the model is set back to what used to be in the view" ,
761+ inject ( [ TestComponentBuilder ] , fakeAsync ( ( tcb : TestComponentBuilder ) => {
762+ var t = `<input type="text" [(ng-model)]="name">` ;
763+ var rootTC ;
764+ tcb . overrideTemplate ( MyComp , t ) . createAsync ( MyComp ) . then (
765+ ( root ) => { rootTC = root ; } ) ;
766+ tick ( ) ;
767+ rootTC . componentInstance . name = "" ;
768+ rootTC . detectChanges ( ) ;
769+
770+ // Type "aa" into the input.
771+ var input = rootTC . query ( By . css ( "input" ) ) . nativeElement ;
772+ input . value = "aa" ;
773+ input . selectionStart = 1 ;
774+ dispatchEvent ( input , "change" ) ;
775+
776+ tick ( ) ;
777+ rootTC . detectChanges ( ) ;
778+ expect ( rootTC . componentInstance . name ) . toEqual ( "aa" ) ;
779+
780+ // Programatically update the input value to be "bb".
781+ rootTC . componentInstance . name = "bb" ;
782+ tick ( ) ;
783+ rootTC . detectChanges ( ) ;
784+ expect ( input . value ) . toEqual ( "bb" ) ;
785+
786+ // Programatically set it back to "aa".
787+ rootTC . componentInstance . name = "aa" ;
788+ tick ( ) ;
789+ rootTC . detectChanges ( ) ;
790+ expect ( input . value ) . toEqual ( "aa" ) ;
791+ } ) ) ) ;
759792 } ) ;
760793 } ) ;
761794}
0 commit comments