@@ -118,6 +118,75 @@ describe('angular.scenario.Application', function() {
118
118
expect ( called ) . toBeTruthy ( ) ;
119
119
} ) ;
120
120
121
+ it ( 'should set rootElement when navigateTo instigates bootstrap' , inject ( function ( $injector , $browser ) {
122
+ var called ;
123
+ var testWindow = {
124
+ document : jqLite ( '<div class="test-foo"></div>' ) [ 0 ] ,
125
+ angular : {
126
+ element : jqLite ,
127
+ service : { } ,
128
+ resumeBootstrap : noop
129
+ }
130
+ } ;
131
+ jqLite ( testWindow . document ) . data ( '$injector' , $injector ) ;
132
+ var resumeBootstrapSpy = spyOn ( testWindow . angular , 'resumeBootstrap' ) . andReturn ( $injector ) ;
133
+
134
+ var injectorGet = $injector . get ;
135
+ spyOn ( $injector , 'get' ) . andCallFake ( function ( name ) {
136
+ switch ( name ) {
137
+ case "$rootElement" : return jqLite ( testWindow . document ) ;
138
+ default : return injectorGet ( name ) ;
139
+ }
140
+ } ) ;
141
+
142
+ app . getWindow_ = function ( ) {
143
+ return testWindow ;
144
+ } ;
145
+ app . navigateTo ( 'http://localhost/' , noop ) ;
146
+ callLoadHandlers ( app ) ;
147
+ expect ( app . rootElement ) . toBe ( testWindow . document ) ;
148
+ expect ( resumeBootstrapSpy ) . toHaveBeenCalled ( ) ;
149
+ dealoc ( testWindow . document ) ;
150
+ } ) ) ;
151
+
152
+ it ( 'should set setup resumeDeferredBootstrap if resumeBootstrap is not yet defined' , inject ( function ( $injector , $browser ) {
153
+ var called ;
154
+ var testWindow = {
155
+ document : jqLite ( '<div class="test-foo"></div>' ) [ 0 ] ,
156
+ angular : {
157
+ element : jqLite ,
158
+ service : { } ,
159
+ resumeBootstrap : null
160
+ }
161
+ } ;
162
+ jqLite ( testWindow . document ) . data ( '$injector' , $injector ) ;
163
+
164
+ var injectorGet = $injector . get ;
165
+ var injectorSpy = spyOn ( $injector , 'get' ) . andCallFake ( function ( name ) {
166
+ switch ( name ) {
167
+ case "$rootElement" : return jqLite ( testWindow . document ) ;
168
+ default : return injectorGet ( name ) ;
169
+ }
170
+ } ) ;
171
+
172
+ app . getWindow_ = function ( ) {
173
+ return testWindow ;
174
+ } ;
175
+ app . navigateTo ( 'http://localhost/' , noop ) ;
176
+ expect ( testWindow . angular . resumeDeferredBootstrap ) . toBeUndefined ( ) ;
177
+ callLoadHandlers ( app ) ;
178
+ expect ( testWindow . angular . resumeDeferredBootstrap ) . toBeDefined ( ) ;
179
+ expect ( app . rootElement ) . toBeUndefined ;
180
+ expect ( injectorSpy ) . not . toHaveBeenCalled ( ) ;
181
+
182
+ var resumeBootstrapSpy = spyOn ( testWindow . angular , 'resumeBootstrap' ) . andReturn ( $injector ) ;
183
+ testWindow . angular . resumeDeferredBootstrap ( ) ;
184
+ expect ( app . rootElement ) . toBe ( testWindow . document ) ;
185
+ expect ( resumeBootstrapSpy ) . toHaveBeenCalled ( ) ;
186
+ expect ( injectorSpy ) . toHaveBeenCalledWith ( "$rootElement" ) ;
187
+ dealoc ( testWindow . document ) ;
188
+ } ) ) ;
189
+
121
190
it ( 'should wait for pending requests in executeAction' , inject ( function ( $injector , $browser ) {
122
191
var called , polled ;
123
192
var handlers = [ ] ;
@@ -144,4 +213,32 @@ describe('angular.scenario.Application', function() {
144
213
handlers [ 0 ] ( ) ;
145
214
dealoc ( testWindow . document ) ;
146
215
} ) ) ;
216
+
217
+ it ( 'should allow explicit rootElement' , inject ( function ( $injector , $browser ) {
218
+ var called , polled ;
219
+ var handlers = [ ] ;
220
+ var testWindow = {
221
+ document : jqLite ( '<div class="test-foo"></div>' ) [ 0 ] ,
222
+ angular : {
223
+ element : jqLite ,
224
+ service : { }
225
+ }
226
+ } ;
227
+ $browser . notifyWhenNoOutstandingRequests = function ( fn ) {
228
+ handlers . push ( fn ) ;
229
+ } ;
230
+ app . rootElement = testWindow . document ;
231
+ jqLite ( testWindow . document ) . data ( '$injector' , $injector ) ;
232
+ app . getWindow_ = function ( ) {
233
+ return testWindow ;
234
+ } ;
235
+ app . executeAction ( function ( $window , $document ) {
236
+ expect ( $window ) . toEqual ( testWindow ) ;
237
+ expect ( $document ) . toBeDefined ( ) ;
238
+ expect ( $document [ 0 ] . className ) . toEqual ( 'test-foo' ) ;
239
+ } ) ;
240
+ expect ( handlers . length ) . toEqual ( 1 ) ;
241
+ handlers [ 0 ] ( ) ;
242
+ dealoc ( testWindow . document ) ;
243
+ } ) ) ;
147
244
} ) ;
0 commit comments