diff options
| author | Vojta Jina | 2011-08-05 01:24:41 +0200 |
|---|---|---|
| committer | Igor Minar | 2011-11-30 11:12:14 -0500 |
| commit | 59adadca086853c5de6867ae853f6f27a3af4bbe (patch) | |
| tree | f56e4501975a7e53475f6e0d7bb606e530983a7b /test/service/xhr.bulkSpec.js | |
| parent | 497839f583ca3dd75583fb996bb764cbd6d7c4ac (diff) | |
| download | angular.js-59adadca086853c5de6867ae853f6f27a3af4bbe.tar.bz2 | |
feat($http): new $http service, removing $xhr.*
Features:
- aborting requests
- more flexible callbacks (per status code)
- custom request headers (per request)
- access to response headers
- custom transform functions (both request, response)
- caching
- shortcut methods (get, head, post, put, delete, patch, jsonp)
- exposing pendingCount()
- setting timeout
Breaks Renaming $xhr to $http
Breaks Takes one parameter now - configuration object
Breaks $xhr.cache removed - use configuration cache: true instead
Breaks $xhr.error, $xhr.bulk removed
Breaks Callback functions get parameters: response, status, headers
Closes #38
Closes #80
Closes #180
Closes #299
Closes #342
Closes #395
Closes #413
Closes #414
Closes #507
Diffstat (limited to 'test/service/xhr.bulkSpec.js')
| -rw-r--r-- | test/service/xhr.bulkSpec.js | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/test/service/xhr.bulkSpec.js b/test/service/xhr.bulkSpec.js deleted file mode 100644 index 6e55b387..00000000 --- a/test/service/xhr.bulkSpec.js +++ /dev/null @@ -1,81 +0,0 @@ -'use strict'; - -describe('$xhr.bulk', function() { - var log; - - beforeEach(inject(function($provide) { - $provide.value('$xhr.error', jasmine.createSpy('$xhr.error')); - $provide.factory('$xhrError', ['$xhr.error', identity]); - $provide.factory('$xhrBulk', ['$xhr.bulk', identity]); - log = ''; - })); - - - function callback(code, response) { - expect(code).toEqual(200); - log = log + toJson(response) + ';'; - } - - - it('should collect requests', inject(function($browser, $xhrBulk) { - $xhrBulk.urls["/"] = {match:/.*/}; - $xhrBulk('GET', '/req1', null, callback); - $xhrBulk('POST', '/req2', {post:'data'}, callback); - - $browser.xhr.expectPOST('/', { - requests:[{method:'GET', url:'/req1', data: null}, - {method:'POST', url:'/req2', data:{post:'data'} }] - }).respond([ - {status:200, response:'first'}, - {status:200, response:'second'} - ]); - $xhrBulk.flush(function() { log += 'DONE';}); - $browser.xhr.flush(); - expect(log).toEqual('"first";"second";DONE'); - })); - - - it('should handle non 200 status code by forwarding to error handler', - inject(function($browser, $xhrBulk, $xhrError) { - $xhrBulk.urls['/'] = {match:/.*/}; - $xhrBulk('GET', '/req1', null, callback); - $xhrBulk('POST', '/req2', {post:'data'}, callback); - - $browser.xhr.expectPOST('/', { - requests:[{method:'GET', url:'/req1', data: null}, - {method:'POST', url:'/req2', data:{post:'data'} }] - }).respond([ - {status:404, response:'NotFound'}, - {status:200, response:'second'} - ]); - $xhrBulk.flush(function() { log += 'DONE';}); - $browser.xhr.flush(); - - expect($xhrError).toHaveBeenCalled(); - var cb = $xhrError.mostRecentCall.args[0].success; - expect(typeof cb).toEqual('function'); - expect($xhrError).toHaveBeenCalledWith( - {url: '/req1', method: 'GET', data: null, success: cb}, - {status: 404, response: 'NotFound'}); - - expect(log).toEqual('"second";DONE'); - })); - - it('should handle non 200 status code by calling error callback if provided', - inject(function($browser, $xhrBulk, $xhrError) { - var callback = jasmine.createSpy('error'); - - $xhrBulk.urls['/'] = {match: /.*/}; - $xhrBulk('GET', '/req1', null, noop, callback); - - $browser.xhr.expectPOST('/', { - requests:[{method: 'GET', url: '/req1', data: null}] - }).respond([{status: 404, response: 'NotFound'}]); - - $xhrBulk.flush(); - $browser.xhr.flush(); - - expect($xhrError).not.toHaveBeenCalled(); - expect(callback).toHaveBeenCalledWith(404, 'NotFound'); - })); -}); |
