| OLD | NEW |
| 1 library angular.mock.http_backend; | 1 part of angular.mock; |
| 2 | 2 |
| 3 import 'dart:async' as dart_async; | |
| 4 import 'dart:convert' show JSON; | |
| 5 import 'dart:html'; | |
| 6 | |
| 7 import 'package:angular/angular.dart'; | |
| 8 import 'package:angular/utils.dart' as utils; | |
| 9 | |
| 10 | |
| 11 class _MockXhr { | 3 class _MockXhr { |
| 12 var method, url, async, reqHeaders, respHeaders; | 4 var $$method, $$url, $$async, $$reqHeaders, $$respHeaders; |
| 13 | 5 |
| 14 void open(method, url, async) { | 6 void open(method, url, async) { |
| 15 this.method = method; | 7 $$method = method; |
| 16 this.url = url; | 8 $$url = url; |
| 17 this.async = async; | 9 $$async = async; |
| 18 reqHeaders = {}; | 10 $$reqHeaders = {}; |
| 19 respHeaders = {}; | 11 $$respHeaders = {}; |
| 20 } | 12 } |
| 21 | 13 |
| 22 var data; | 14 var $$data; |
| 23 | 15 |
| 24 void send(data) { | 16 void send(data) { |
| 25 data = data; | 17 $$data = data; |
| 26 } | 18 } |
| 27 | 19 |
| 28 void setRequestHeader(key, value) { | 20 void setRequestHeader(key, value) { |
| 29 reqHeaders[key] = value; | 21 $$reqHeaders[key] = value; |
| 30 } | 22 } |
| 31 | 23 |
| 32 String getResponseHeader(name) { | 24 String getResponseHeader(name) { |
| 33 // the lookup must be case insensitive, that's why we try two quick | 25 // the lookup must be case insensitive, that's why we try two quick |
| 34 // lookups and full scan at last | 26 // lookups and full scan at last |
| 35 if (respHeaders.containsKey(name)) return respHeaders[name]; | 27 if ($$respHeaders.containsKey(name)) return $$respHeaders[name]; |
| 36 | 28 |
| 37 name = name.toLowerCase(); | 29 name = name.toLowerCase(); |
| 38 if (respHeaders.containsKey(name)) return respHeaders[name]; | 30 if ($$respHeaders.containsKey(name)) return $$respHeaders[name]; |
| 39 | 31 |
| 40 String header = null; | 32 String header = null; |
| 41 respHeaders.forEach((headerName, headerVal) { | 33 $$respHeaders.forEach((headerName, headerVal) { |
| 42 if (header != null) return; | 34 if (header != null) return; |
| 43 if (headerName.toLowerCase()) header = headerVal; | 35 if (headerName.toLowerCase()) header = headerVal; |
| 44 }); | 36 }); |
| 45 return header; | 37 return header; |
| 46 } | 38 } |
| 47 | 39 |
| 48 getAllResponseHeaders() { | 40 getAllResponseHeaders() { |
| 49 if (respHeaders == null) return ''; | 41 if ($$respHeaders == null) return ''; |
| 50 | 42 |
| 51 var lines = []; | 43 var lines = []; |
| 52 | 44 |
| 53 respHeaders.forEach((key, value) { | 45 $$respHeaders.forEach((key, value) { |
| 54 lines.add("$key: $value"); | 46 lines.add("$key: $value"); |
| 55 }); | 47 }); |
| 56 return lines.join('\n'); | 48 return lines.join('\n'); |
| 57 } | 49 } |
| 58 | 50 |
| 59 // noop | 51 // noop |
| 60 abort() {} | 52 abort() {} |
| 61 } | 53 } |
| 62 | 54 |
| 63 /** | 55 /** |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 162 |
| 171 var prettyPrint = (data) { | 163 var prettyPrint = (data) { |
| 172 return (data is String || data is Function || data is RegExp) | 164 return (data is String || data is Function || data is RegExp) |
| 173 ? data | 165 ? data |
| 174 : JSON.encode(data); | 166 : JSON.encode(data); |
| 175 }; | 167 }; |
| 176 | 168 |
| 177 var wrapResponse = (wrapped) { | 169 var wrapResponse = (wrapped) { |
| 178 var handleResponse = () { | 170 var handleResponse = () { |
| 179 var response = wrapped.response(method, url, data, headers); | 171 var response = wrapped.response(method, url, data, headers); |
| 180 xhr.respHeaders = response[2]; | 172 xhr.$$respHeaders = response[2]; |
| 181 utils.relaxFnApply(callback, [response[0], response[1], | 173 utils.relaxFnApply(callback, [response[0], response[1], |
| 182 xhr.getAllResponseHeaders()]); | 174 xhr.getAllResponseHeaders()]); |
| 183 }; | 175 }; |
| 184 | 176 |
| 185 var handleTimeout = () { | 177 var handleTimeout = () { |
| 186 for (var i = 0; i < responses.length; i++) { | 178 for (var i = 0; i < responses.length; i++) { |
| 187 if (identical(responses[i], handleResponse)) { | 179 if (identical(responses[i], handleResponse)) { |
| 188 responses.removeAt(i); | 180 responses.removeAt(i); |
| 189 callback(-1, null, ''); | 181 callback(-1, null, ''); |
| 190 break; | 182 break; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 chain = new _Chain(respond: (status, data, headers) { | 245 chain = new _Chain(respond: (status, data, headers) { |
| 254 definition.response = _createResponse(status, data, headers); | 246 definition.response = _createResponse(status, data, headers); |
| 255 }); | 247 }); |
| 256 | 248 |
| 257 definitions.add(definition); | 249 definitions.add(definition); |
| 258 return chain; | 250 return chain; |
| 259 } | 251 } |
| 260 | 252 |
| 261 /** | 253 /** |
| 262 * @ngdoc method | 254 * @ngdoc method |
| 263 * @name ngMock.httpBackend#whenGET | 255 * @name ngMock.$httpBackend#whenGET |
| 264 * @methodOf ngMock.httpBackend | 256 * @methodOf ngMock.$httpBackend |
| 265 * @description | 257 * @description |
| 266 * Creates a new backend definition for GET requests. For more info see `when(
)`. | 258 * Creates a new backend definition for GET requests. For more info see `when(
)`. |
| 267 * | 259 * |
| 268 * @param {string|RegExp} url HTTP url. | 260 * @param {string|RegExp} url HTTP url. |
| 269 * @param {(Object|function(Object))=} headers HTTP headers. | 261 * @param {(Object|function(Object))=} headers HTTP headers. |
| 270 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 262 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 271 * request is handled. | 263 * request is handled. |
| 272 */ | 264 */ |
| 273 _Chain whenGET(url, [headers]) => when('GET', url, null, headers); | 265 _Chain whenGET(url, [headers]) => when('GET', url, null, headers); |
| 274 | 266 |
| 275 /** | 267 /** |
| 276 * @ngdoc method | 268 * @ngdoc method |
| 277 * @name ngMock.httpBackend#whenDELETE | 269 * @name ngMock.$httpBackend#whenDELETE |
| 278 * @methodOf ngMock.httpBackend | 270 * @methodOf ngMock.$httpBackend |
| 279 * @description | 271 * @description |
| 280 * Creates a new backend definition for DELETE requests. For more info see `wh
en()`. | 272 * Creates a new backend definition for DELETE requests. For more info see `wh
en()`. |
| 281 * | 273 * |
| 282 * @param {string|RegExp} url HTTP url. | 274 * @param {string|RegExp} url HTTP url. |
| 283 * @param {(Object|function(Object))=} headers HTTP headers. | 275 * @param {(Object|function(Object))=} headers HTTP headers. |
| 284 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 276 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 285 * request is handled. | 277 * request is handled. |
| 286 */ | 278 */ |
| 287 _Chain whenDELETE(url, [headers]) => when('DELETE', url, null, headers); | 279 _Chain whenDELETE(url, [headers]) => when('DELETE', url, null, headers); |
| 288 | 280 |
| 289 /** | 281 /** |
| 290 * @ngdoc method | 282 * @ngdoc method |
| 291 * @name ngMock.httpBackend#whenJSONP | 283 * @name ngMock.$httpBackend#whenJSONP |
| 292 * @methodOf ngMock.httpBackend | 284 * @methodOf ngMock.$httpBackend |
| 293 * @description | 285 * @description |
| 294 * Creates a new backend definition for JSONP requests. For more info see `whe
n()`. | 286 * Creates a new backend definition for JSONP requests. For more info see `whe
n()`. |
| 295 * | 287 * |
| 296 * @param {string|RegExp} url HTTP url. | 288 * @param {string|RegExp} url HTTP url. |
| 297 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 289 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 298 * request is handled. | 290 * request is handled. |
| 299 */ | 291 */ |
| 300 _Chain whenJSONP(url, [headers]) => when('JSONP', url, null, headers); | 292 _Chain whenJSONP(url, [headers]) => when('JSONP', url, null, headers); |
| 301 | 293 |
| 302 /** | 294 /** |
| 303 * @ngdoc method | 295 * @ngdoc method |
| 304 * @name ngMock.httpBackend#whenPUT | 296 * @name ngMock.$httpBackend#whenPUT |
| 305 * @methodOf ngMock.httpBackend | 297 * @methodOf ngMock.$httpBackend |
| 306 * @description | 298 * @description |
| 307 * Creates a new backend definition for PUT requests. For more info see `when
()`. | 299 * Creates a new backend definition for PUT requests. For more info see `when
()`. |
| 308 * | 300 * |
| 309 * @param {string|RegExp} url HTTP url. | 301 * @param {string|RegExp} url HTTP url. |
| 310 * @param {(string|RegExp)=} data HTTP request body. | 302 * @param {(string|RegExp)=} data HTTP request body. |
| 311 * @param {(Object|function(Object))=} headers HTTP headers. | 303 * @param {(Object|function(Object))=} headers HTTP headers. |
| 312 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 304 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 313 * request is handled. | 305 * request is handled. |
| 314 */ | 306 */ |
| 315 _Chain whenPUT(url, [data, headers]) => when('PUT', url, data, headers); | 307 _Chain whenPUT(url, [data, headers]) => when('PUT', url, data, headers); |
| 316 | 308 |
| 317 /** | 309 /** |
| 318 * @ngdoc method | 310 * @ngdoc method |
| 319 * @name ngMock.httpBackend#whenPOST | 311 * @name ngMock.$httpBackend#whenPOST |
| 320 * @methodOf ngMock.httpBackend | 312 * @methodOf ngMock.$httpBackend |
| 321 * @description | 313 * @description |
| 322 * Creates a new backend definition for POST requests. For more info see `when
()`. | 314 * Creates a new backend definition for POST requests. For more info see `when
()`. |
| 323 * | 315 * |
| 324 * @param {string|RegExp} url HTTP url. | 316 * @param {string|RegExp} url HTTP url. |
| 325 * @param {(string|RegExp)=} data HTTP request body. | 317 * @param {(string|RegExp)=} data HTTP request body. |
| 326 * @param {(Object|function(Object))=} headers HTTP headers. | 318 * @param {(Object|function(Object))=} headers HTTP headers. |
| 327 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 319 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 328 * request is handled. | 320 * request is handled. |
| 329 */ | 321 */ |
| 330 _Chain whenPOST(url, [data, headers]) => when('POST', url, data, headers); | 322 _Chain whenPOST(url, [data, headers]) => when('POST', url, data, headers); |
| 331 | 323 |
| 332 _Chain whenPATCH(url, [data, headers]) => when('PATCH', url, data, headers); | 324 _Chain whenPATCH(url, [data, headers]) => when('PATCH', url, data, headers); |
| 333 | 325 |
| 334 /** | 326 /** |
| 335 * @ngdoc method | 327 * @ngdoc method |
| 336 * @name ngMock.httpBackend#whenHEAD | 328 * @name ngMock.$httpBackend#whenHEAD |
| 337 * @methodOf ngMock.httpBackend | 329 * @methodOf ngMock.$httpBackend |
| 338 * @description | 330 * @description |
| 339 * Creates a new backend definition for HEAD requests. For more info see `when
()`. | 331 * Creates a new backend definition for HEAD requests. For more info see `when
()`. |
| 340 * | 332 * |
| 341 * @param {string|RegExp} url HTTP url. | 333 * @param {string|RegExp} url HTTP url. |
| 342 * @param {(Object|function(Object))=} headers HTTP headers. | 334 * @param {(Object|function(Object))=} headers HTTP headers. |
| 343 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 335 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 344 * request is handled. | 336 * request is handled. |
| 345 */ | 337 */ |
| 346 | 338 |
| 347 /** | 339 /** |
| 348 * @ngdoc method | 340 * @ngdoc method |
| 349 * @name ngMock.httpBackend#expect | 341 * @name ngMock.$httpBackend#expect |
| 350 * @methodOf ngMock.httpBackend | 342 * @methodOf ngMock.$httpBackend |
| 351 * @description | 343 * @description |
| 352 * Creates a new request expectation. | 344 * Creates a new request expectation. |
| 353 * | 345 * |
| 354 * @param {string} method HTTP method. | 346 * @param {string} method HTTP method. |
| 355 * @param {string|RegExp} url HTTP url. | 347 * @param {string|RegExp} url HTTP url. |
| 356 * @param {(string|RegExp)=} data HTTP request body. | 348 * @param {(string|RegExp)=} data HTTP request body. |
| 357 * @param {(Object|function(Object))=} headers HTTP headers or function that r
eceives http header | 349 * @param {(Object|function(Object))=} headers HTTP headers or function that r
eceives http header |
| 358 * object and returns true if the headers match the current expectation. | 350 * object and returns true if the headers match the current expectation. |
| 359 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 351 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 360 * request is handled. | 352 * request is handled. |
| 361 * | 353 * |
| 362 * - respond – `{function([status,] data[, headers])|function(function(method
, url, data, headers)}` | 354 * - respond – `{function([status,] data[, headers])|function(function(method
, url, data, headers)}` |
| 363 * – The respond method takes a set of static data to be returned or a func
tion that can return | 355 * – The respond method takes a set of static data to be returned or a func
tion that can return |
| 364 * an array containing response status (number), response data (string) and
response headers | 356 * an array containing response status (number), response data (string) and
response headers |
| 365 * (Object). | 357 * (Object). |
| 366 */ | 358 */ |
| 367 _Chain expect(method, [url, data, headers]) { | 359 _Chain expect(method, [url, data, headers]) { |
| 368 var expectation = new MockHttpExpectation(method, url, data, headers); | 360 var expectation = new MockHttpExpectation(method, url, data, headers); |
| 369 expectations.add(expectation); | 361 expectations.add(expectation); |
| 370 return new _Chain(respond: (status, data, headers) { | 362 return new _Chain(respond: (status, data, headers) { |
| 371 expectation.response = _createResponse(status, data, headers); | 363 expectation.response = _createResponse(status, data, headers); |
| 372 }); | 364 }); |
| 373 } | 365 } |
| 374 | 366 |
| 375 | 367 |
| 376 /** | 368 /** |
| 377 * @ngdoc method | 369 * @ngdoc method |
| 378 * @name ngMock.httpBackend#expectGET | 370 * @name ngMock.$httpBackend#expectGET |
| 379 * @methodOf ngMock.httpBackend | 371 * @methodOf ngMock.$httpBackend |
| 380 * @description | 372 * @description |
| 381 * Creates a new request expectation for GET requests. For more info see `expe
ct()`. | 373 * Creates a new request expectation for GET requests. For more info see `expe
ct()`. |
| 382 * | 374 * |
| 383 * @param {string|RegExp} url HTTP url. | 375 * @param {string|RegExp} url HTTP url. |
| 384 * @param {Object=} headers HTTP headers. | 376 * @param {Object=} headers HTTP headers. |
| 385 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 377 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 386 * request is handled. See #expect for more info. | 378 * request is handled. See #expect for more info. |
| 387 */ | 379 */ |
| 388 _Chain expectGET(url, [headers]) => expect('GET', url, null, headers); | 380 _Chain expectGET(url, [headers]) => expect('GET', url, null, headers); |
| 389 | 381 |
| 390 /** | 382 /** |
| 391 * @ngdoc method | 383 * @ngdoc method |
| 392 * @name ngMock.httpBackend#expectDELETE | 384 * @name ngMock.$httpBackend#expectDELETE |
| 393 * @methodOf ngMock.httpBackend | 385 * @methodOf ngMock.$httpBackend |
| 394 * @description | 386 * @description |
| 395 * Creates a new request expectation for DELETE requests. For more info see `e
xpect()`. | 387 * Creates a new request expectation for DELETE requests. For more info see `e
xpect()`. |
| 396 * | 388 * |
| 397 * @param {string|RegExp} url HTTP url. | 389 * @param {string|RegExp} url HTTP url. |
| 398 * @param {Object=} headers HTTP headers. | 390 * @param {Object=} headers HTTP headers. |
| 399 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 391 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 400 * request is handled. | 392 * request is handled. |
| 401 */ | 393 */ |
| 402 _Chain expectDELETE(url, [headers]) => expect('DELETE', url, null, headers); | 394 _Chain expectDELETE(url, [headers]) => expect('DELETE', url, null, headers); |
| 403 | 395 |
| 404 /** | 396 /** |
| 405 * @ngdoc method | 397 * @ngdoc method |
| 406 * @name ngMock.httpBackend#expectJSONP | 398 * @name ngMock.$httpBackend#expectJSONP |
| 407 * @methodOf ngMock.httpBackend | 399 * @methodOf ngMock.$httpBackend |
| 408 * @description | 400 * @description |
| 409 * Creates a new request expectation for JSONP requests. For more info see `ex
pect()`. | 401 * Creates a new request expectation for JSONP requests. For more info see `ex
pect()`. |
| 410 * | 402 * |
| 411 * @param {string|RegExp} url HTTP url. | 403 * @param {string|RegExp} url HTTP url. |
| 412 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 404 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 413 * request is handled. | 405 * request is handled. |
| 414 */ | 406 */ |
| 415 _Chain expectJSONP(url, [headers]) => expect('JSONP', url, null, headers); | 407 _Chain expectJSONP(url, [headers]) => expect('JSONP', url, null, headers); |
| 416 | 408 |
| 417 /** | 409 /** |
| 418 * @ngdoc method | 410 * @ngdoc method |
| 419 * @name ngMock.httpBackend#expectPUT | 411 * @name ngMock.$httpBackend#expectPUT |
| 420 * @methodOf ngMock.httpBackend | 412 * @methodOf ngMock.$httpBackend |
| 421 * @description | 413 * @description |
| 422 * Creates a new request expectation for PUT requests. For more info see `expe
ct()`. | 414 * Creates a new request expectation for PUT requests. For more info see `expe
ct()`. |
| 423 * | 415 * |
| 424 * @param {string|RegExp} url HTTP url. | 416 * @param {string|RegExp} url HTTP url. |
| 425 * @param {(string|RegExp)=} data HTTP request body. | 417 * @param {(string|RegExp)=} data HTTP request body. |
| 426 * @param {Object=} headers HTTP headers. | 418 * @param {Object=} headers HTTP headers. |
| 427 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 419 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 428 * request is handled. | 420 * request is handled. |
| 429 */ | 421 */ |
| 430 _Chain expectPUT(url, [data, headers]) => expect('PUT', url, data, headers); | 422 _Chain expectPUT(url, [data, headers]) => expect('PUT', url, data, headers); |
| 431 | 423 |
| 432 /** | 424 /** |
| 433 * @ngdoc method | 425 * @ngdoc method |
| 434 * @name ngMock.httpBackend#expectPOST | 426 * @name ngMock.$httpBackend#expectPOST |
| 435 * @methodOf ngMock.httpBackend | 427 * @methodOf ngMock.$httpBackend |
| 436 * @description | 428 * @description |
| 437 * Creates a new request expectation for POST requests. For more info see `exp
ect()`. | 429 * Creates a new request expectation for POST requests. For more info see `exp
ect()`. |
| 438 * | 430 * |
| 439 * @param {string|RegExp} url HTTP url. | 431 * @param {string|RegExp} url HTTP url. |
| 440 * @param {(string|RegExp)=} data HTTP request body. | 432 * @param {(string|RegExp)=} data HTTP request body. |
| 441 * @param {Object=} headers HTTP headers. | 433 * @param {Object=} headers HTTP headers. |
| 442 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 434 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 443 * request is handled. | 435 * request is handled. |
| 444 */ | 436 */ |
| 445 _Chain expectPOST(url, [data, headers]) => expect('POST', url, data, headers); | 437 _Chain expectPOST(url, [data, headers]) => expect('POST', url, data, headers); |
| 446 | 438 |
| 447 /** | 439 /** |
| 448 * @ngdoc method | 440 * @ngdoc method |
| 449 * @name ngMock.httpBackend#expectPATCH | 441 * @name ngMock.$httpBackend#expectPATCH |
| 450 * @methodOf ngMock.httpBackend | 442 * @methodOf ngMock.$httpBackend |
| 451 * @description | 443 * @description |
| 452 * Creates a new request expectation for PATCH requests. For more info see `ex
pect()`. | 444 * Creates a new request expectation for PATCH requests. For more info see `ex
pect()`. |
| 453 * | 445 * |
| 454 * @param {string|RegExp} url HTTP url. | 446 * @param {string|RegExp} url HTTP url. |
| 455 * @param {(string|RegExp)=} data HTTP request body. | 447 * @param {(string|RegExp)=} data HTTP request body. |
| 456 * @param {Object=} headers HTTP headers. | 448 * @param {Object=} headers HTTP headers. |
| 457 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 449 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 458 * request is handled. | 450 * request is handled. |
| 459 */ | 451 */ |
| 460 _Chain expectPATCH(url, [data, headers]) => expect('PATCH', url, data, headers
); | 452 _Chain expectPATCH(url, [data, headers]) => expect('PATCH', url, data, headers
); |
| 461 | 453 |
| 462 /** | 454 /** |
| 463 * @ngdoc method | 455 * @ngdoc method |
| 464 * @name ngMock.httpBackend#expectHEAD | 456 * @name ngMock.$httpBackend#expectHEAD |
| 465 * @methodOf ngMock.httpBackend | 457 * @methodOf ngMock.$httpBackend |
| 466 * @description | 458 * @description |
| 467 * Creates a new request expectation for HEAD requests. For more info see `exp
ect()`. | 459 * Creates a new request expectation for HEAD requests. For more info see `exp
ect()`. |
| 468 * | 460 * |
| 469 * @param {string|RegExp} url HTTP url. | 461 * @param {string|RegExp} url HTTP url. |
| 470 * @param {Object=} headers HTTP headers. | 462 * @param {Object=} headers HTTP headers. |
| 471 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched | 463 * @returns {requestHandler} Returns an object with `respond` method that cont
rol how a matched |
| 472 * request is handled. | 464 * request is handled. |
| 473 */ | 465 */ |
| 474 | 466 |
| 475 /** | 467 /** |
| 476 * @ngdoc method | 468 * @ngdoc method |
| 477 * @name ngMock.httpBackend#flush | 469 * @name ngMock.$httpBackend#flush |
| 478 * @methodOf ngMock.httpBackend | 470 * @methodOf ngMock.$httpBackend |
| 479 * @description | 471 * @description |
| 480 * Flushes all pending requests using the trained responses. | 472 * Flushes all pending requests using the trained responses. |
| 481 * | 473 * |
| 482 * @param {number=} count Number of responses to flush (in the order they arri
ved). If undefined, | 474 * @param {number=} count Number of responses to flush (in the order they arri
ved). If undefined, |
| 483 * all pending requests will be flushed. If there are no pending requests wh
en the flush method | 475 * all pending requests will be flushed. If there are no pending requests wh
en the flush method |
| 484 * is called an exception is thrown (as this typically a sign of programming
error). | 476 * is called an exception is thrown (as this typically a sign of programming
error). |
| 485 */ | 477 */ |
| 486 void flush([count]) { | 478 void flush([count]) { |
| 487 if (responses.isEmpty) throw ['No pending request to flush !']; | 479 if (responses.isEmpty) throw ['No pending request to flush !']; |
| 488 | 480 |
| 489 if (count != null) { | 481 if (count != null) { |
| 490 while (count-- > 0) { | 482 while (count-- > 0) { |
| 491 if (responses.isEmpty) throw ['No more pending request to flush !']; | 483 if (responses.isEmpty) throw ['No more pending request to flush !']; |
| 492 responses.removeAt(0)(); | 484 responses.removeAt(0)(); |
| 493 } | 485 } |
| 494 } else { | 486 } else { |
| 495 while (!responses.isEmpty) { | 487 while (!responses.isEmpty) { |
| 496 responses.removeAt(0)(); | 488 responses.removeAt(0)(); |
| 497 } | 489 } |
| 498 } | 490 } |
| 499 verifyNoOutstandingExpectation(); | 491 verifyNoOutstandingExpectation(); |
| 500 } | 492 } |
| 501 | 493 |
| 502 | 494 |
| 503 /** | 495 /** |
| 504 * @ngdoc method | 496 * @ngdoc method |
| 505 * @name ngMock.httpBackend#verifyNoOutstandingExpectation | 497 * @name ngMock.$httpBackend#verifyNoOutstandingExpectation |
| 506 * @methodOf ngMock.httpBackend | 498 * @methodOf ngMock.$httpBackend |
| 507 * @description | 499 * @description |
| 508 * Verifies that all of the requests defined via the `expect` api were made. I
f any of the | 500 * Verifies that all of the requests defined via the `expect` api were made. I
f any of the |
| 509 * requests were not made, verifyNoOutstandingExpectation throws an exception. | 501 * requests were not made, verifyNoOutstandingExpectation throws an exception. |
| 510 * | 502 * |
| 511 * Typically, you would call this method following each test case that asserts
requests using an | 503 * Typically, you would call this method following each test case that asserts
requests using an |
| 512 * "afterEach" clause. | 504 * "afterEach" clause. |
| 513 * | 505 * |
| 514 * <pre> | 506 * <pre> |
| 515 * afterEach(httpBackend.verifyNoOutstandingExpectation); | 507 * afterEach($httpBackend.verifyNoOutstandingExpectation); |
| 516 * </pre> | 508 * </pre> |
| 517 */ | 509 */ |
| 518 void verifyNoOutstandingExpectation() { | 510 void verifyNoOutstandingExpectation() { |
| 519 if (!expectations.isEmpty) { | 511 if (!expectations.isEmpty) { |
| 520 throw ['Unsatisfied requests: ${expectations.join(', ')}']; | 512 throw ['Unsatisfied requests: ${expectations.join(', ')}']; |
| 521 } | 513 } |
| 522 } | 514 } |
| 523 | 515 |
| 524 | 516 |
| 525 /** | 517 /** |
| 526 * @ngdoc method | 518 * @ngdoc method |
| 527 * @name ngMock.httpBackend#verifyNoOutstandingRequest | 519 * @name ngMock.$httpBackend#verifyNoOutstandingRequest |
| 528 * @methodOf ngMock.httpBackend | 520 * @methodOf ngMock.$httpBackend |
| 529 * @description | 521 * @description |
| 530 * Verifies that there are no outstanding requests that need to be flushed. | 522 * Verifies that there are no outstanding requests that need to be flushed. |
| 531 * | 523 * |
| 532 * Typically, you would call this method following each test case that asserts
requests using an | 524 * Typically, you would call this method following each test case that asserts
requests using an |
| 533 * "afterEach" clause. | 525 * "afterEach" clause. |
| 534 * | 526 * |
| 535 * <pre> | 527 * <pre> |
| 536 * afterEach(httpBackend.verifyNoOutstandingRequest); | 528 * afterEach($httpBackend.verifyNoOutstandingRequest); |
| 537 * </pre> | 529 * </pre> |
| 538 */ | 530 */ |
| 539 void verifyNoOutstandingRequest() { | 531 void verifyNoOutstandingRequest() { |
| 540 if (!responses.isEmpty) throw ['Unflushed requests: ${responses.length}']; | 532 if (!responses.isEmpty) throw ['Unflushed requests: ${responses.length}']; |
| 541 } | 533 } |
| 542 | 534 |
| 543 | 535 |
| 544 /** | 536 /** |
| 545 * @ngdoc method | 537 * @ngdoc method |
| 546 * @name ngMock.httpBackend#resetExpectations | 538 * @name ngMock.$httpBackend#resetExpectations |
| 547 * @methodOf ngMock.httpBackend | 539 * @methodOf ngMock.$httpBackend |
| 548 * @description | 540 * @description |
| 549 * Resets all request expectations, but preserves all backend definitions. Typ
ically, you would | 541 * Resets all request expectations, but preserves all backend definitions. Typ
ically, you would |
| 550 * call resetExpectations during a multiple-phase test when you want to reuse
the same instance of | 542 * call resetExpectations during a multiple-phase test when you want to reuse
the same instance of |
| 551 * httpBackend mock. | 543 * $httpBackend mock. |
| 552 */ | 544 */ |
| 553 void resetExpectations() { | 545 void resetExpectations() { |
| 554 expectations.length = 0; | 546 expectations.length = 0; |
| 555 responses.length = 0; | 547 responses.length = 0; |
| 556 } | 548 } |
| 557 } | 549 } |
| 558 | 550 |
| 559 /** | 551 /** |
| 560 * Mock implementation of the [HttpRequest] object returned from the HttpBackend
. | 552 * Mock implementation of the [HttpRequest] object returned from the HttpBackend
. |
| 561 */ | 553 */ |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 final String type = null; | 618 final String type = null; |
| 627 | 619 |
| 628 bool cancelBubble = false; | 620 bool cancelBubble = false; |
| 629 | 621 |
| 630 MockProgressEvent(MockHttpRequest this.currentTarget); | 622 MockProgressEvent(MockHttpRequest this.currentTarget); |
| 631 | 623 |
| 632 void preventDefault() {} | 624 void preventDefault() {} |
| 633 void stopImmediatePropagation() {} | 625 void stopImmediatePropagation() {} |
| 634 void stopPropagation() {} | 626 void stopPropagation() {} |
| 635 } | 627 } |
| OLD | NEW |