@@ -114,47 +114,59 @@ describe('$templateRequest', function() {
114
114
expect ( $templateCache . get ( 'tpl.html' ) ) . toBe ( 'matias' ) ;
115
115
} ) ) ;
116
116
117
- it ( 'should throw an error when the template is not found' ,
118
- inject ( function ( $exceptionHandler , $httpBackend , $rootScope , $templateRequest ) {
119
- $httpBackend . expectGET ( 'tpl.html' ) . respond ( 404 , '' , { } , 'Not found' ) ;
117
+ it ( 'should call `$exceptionHandler` on request error' , function ( ) {
118
+ module ( function ( $exceptionHandlerProvider ) {
119
+ $exceptionHandlerProvider . mode ( 'log' ) ;
120
+ } ) ;
120
121
121
- $templateRequest ( 'tpl.html' ) . catch ( noop ) ;
122
+ inject ( function ( $exceptionHandler , $httpBackend , $templateRequest ) {
123
+ $httpBackend . expectGET ( 'tpl.html' ) . respond ( 404 , '' , { } , 'Not Found' ) ;
124
+
125
+ var err ;
126
+ $templateRequest ( 'tpl.html' ) . catch ( function ( reason ) { err = reason ; } ) ;
122
127
$httpBackend . flush ( ) ;
123
128
129
+ expect ( err . message ) . toMatch ( new RegExp (
130
+ '^\\[\\$compile:tpload] Failed to load template: tpl\\.html ' +
131
+ '\\(HTTP status: 404 Not Found\\)' ) ) ;
124
132
expect ( $exceptionHandler . errors [ 0 ] . message ) . toMatch ( new RegExp (
125
133
'^\\[\\$compile:tpload] Failed to load template: tpl\\.html ' +
126
- '\\(HTTP status: 404 Not found\\)' ) ) ;
127
- } )
128
- ) ;
129
-
130
- it ( 'should not throw when the template is not found and ignoreRequestError is true' ,
131
- inject ( function ( $rootScope , $templateRequest , $httpBackend ) {
132
-
133
- $httpBackend . expectGET ( 'tpl.html' ) . respond ( 404 ) ;
134
-
135
- var err ;
136
- $templateRequest ( 'tpl.html' , true ) . catch ( function ( reason ) { err = reason ; } ) ;
137
-
138
- $rootScope . $digest ( ) ;
139
- $httpBackend . flush ( ) ;
134
+ '\\(HTTP status: 404 Not Found\\)' ) ) ;
135
+ } ) ;
136
+ } ) ;
140
137
141
- expect ( err . status ) . toBe ( 404 ) ;
142
- } ) ) ;
138
+ it ( 'should not call `$exceptionHandler` on request error when `ignoreRequestError` is true' ,
139
+ function ( ) {
140
+ module ( function ( $exceptionHandlerProvider ) {
141
+ $exceptionHandlerProvider . mode ( 'log' ) ;
142
+ } ) ;
143
143
144
- it ( 'should not throw an error when the template is empty' ,
145
- inject ( function ( $rootScope , $templateRequest , $httpBackend ) {
144
+ inject ( function ( $exceptionHandler , $httpBackend , $templateRequest ) {
145
+ $httpBackend . expectGET ( 'tpl.html' ) . respond ( 404 ) ;
146
146
147
- $httpBackend . expectGET ( 'tpl.html' ) . respond ( '' ) ;
147
+ var err ;
148
+ $templateRequest ( 'tpl.html' , true ) . catch ( function ( reason ) { err = reason ; } ) ;
149
+ $httpBackend . flush ( ) ;
148
150
149
- $templateRequest ( 'tpl.html' ) ;
151
+ expect ( err . status ) . toBe ( 404 ) ;
152
+ expect ( $exceptionHandler . errors ) . toEqual ( [ ] ) ;
153
+ } ) ;
154
+ }
155
+ ) ;
150
156
151
- $rootScope . $digest ( ) ;
157
+ it ( 'should not call `$exceptionHandler` when the template is empty' ,
158
+ inject ( function ( $exceptionHandler , $httpBackend , $rootScope , $templateRequest ) {
159
+ $httpBackend . expectGET ( 'tpl.html' ) . respond ( '' ) ;
152
160
153
- expect ( function ( ) {
161
+ var onError = jasmine . createSpy ( 'onError' ) ;
162
+ $templateRequest ( 'tpl.html' ) . catch ( onError ) ;
154
163
$rootScope . $digest ( ) ;
155
164
$httpBackend . flush ( ) ;
156
- } ) . not . toThrow ( ) ;
157
- } ) ) ;
165
+
166
+ expect ( onError ) . not . toHaveBeenCalled ( ) ;
167
+ expect ( $exceptionHandler . errors ) . toEqual ( [ ] ) ;
168
+ } )
169
+ ) ;
158
170
159
171
it ( 'should accept empty templates and refuse null or undefined templates in cache' ,
160
172
inject ( function ( $rootScope , $templateRequest , $templateCache , $sce ) {
0 commit comments