@@ -50,6 +50,14 @@ describe('uiView', function () {
50
50
template : 'hState inner template'
51
51
}
52
52
}
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>'
53
61
} ;
54
62
55
63
beforeEach ( module ( function ( $stateProvider ) {
@@ -61,7 +69,9 @@ describe('uiView', function () {
61
69
. state ( 'e' , eState )
62
70
. state ( 'e.f' , fState )
63
71
. state ( 'g' , gState )
64
- . state ( 'g.h' , hState ) ;
72
+ . state ( 'g.h' , hState )
73
+ . state ( 'i' , iState )
74
+ . state ( 'j' , jState ) ;
65
75
} ) ) ;
66
76
67
77
beforeEach ( inject ( function ( $rootScope , _$compile_ ) {
@@ -153,6 +163,41 @@ describe('uiView', function () {
153
163
154
164
expect ( elem [ 0 ] . querySelector ( '.test' ) . innerText ) . toBe ( content ) ;
155
165
} ) ) ;
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
+ } ) ) ;
156
201
} ) ;
157
202
158
203
} ) ;
0 commit comments