@@ -50,6 +50,14 @@ describe('uiView', function () {
5050 template : 'hState inner template'
5151 }
5252 }
53+ } ,
54+ iState = {
55+ template : '<div ui-view>' +
56+ '<ul><li ng-repeat="item in items">{{item}}</li></ul>' +
57+ '</div>'
58+ } ,
59+ jState = {
60+ template : '<span ng-class="test">jState</span>'
5361 } ;
5462
5563 beforeEach ( module ( function ( $stateProvider ) {
@@ -61,7 +69,9 @@ describe('uiView', function () {
6169 . state ( 'e' , eState )
6270 . state ( 'e.f' , fState )
6371 . state ( 'g' , gState )
64- . state ( 'g.h' , hState ) ;
72+ . state ( 'g.h' , hState )
73+ . state ( 'i' , iState )
74+ . state ( 'j' , jState ) ;
6575 } ) ) ;
6676
6777 beforeEach ( inject ( function ( $rootScope , _$compile_ ) {
@@ -153,6 +163,41 @@ describe('uiView', function () {
153163
154164 expect ( elem [ 0 ] . querySelector ( '.test' ) . innerText ) . toBe ( content ) ;
155165 } ) ) ;
166+
167+ // related to issue #435
168+ it ( 'initial view should be transcluded once to prevent breaking other directives' , inject ( function ( $state , $q ) {
169+ scope . items = [ "I" , "am" , "a" , "list" , "of" , "items" ] ;
170+
171+ elem . append ( $compile ( '<div ui-view></div>' ) ( scope ) ) ;
172+
173+ // transition to state that has an initial view
174+ $state . transitionTo ( iState ) ;
175+ $q . flush ( ) ;
176+
177+ // verify if ng-repeat has been compiled
178+ expect ( elem . find ( 'li' ) . length ) . toBe ( scope . items . length ) ;
179+
180+ // transition to another state that replace the initial content
181+ $state . transitionTo ( jState ) ;
182+ $q . flush ( ) ;
183+
184+ expect ( elem . text ( ) ) . toBe ( 'jState' ) ;
185+
186+ // transition back to the state with empty subview and the initial view
187+ $state . transitionTo ( iState ) ;
188+ $q . flush ( ) ;
189+
190+ // verify if the initial view is correct
191+ expect ( elem . find ( 'li' ) . length ) . toBe ( scope . items . length ) ;
192+
193+ // change scope properties
194+ scope . $apply ( function ( ) {
195+ scope . items . push ( "." , "Working?" ) ;
196+ } ) ;
197+
198+ // verify if the initial view has been updated
199+ expect ( elem . find ( 'li' ) . length ) . toBe ( scope . items . length ) ;
200+ } ) ) ;
156201 } ) ;
157202
158203} ) ;
0 commit comments