Index: third_party/pkg/angular/test/core_dom/http_spec.dart |
diff --git a/third_party/pkg/angular/test/core_dom/http_spec.dart b/third_party/pkg/angular/test/core_dom/http_spec.dart |
index bf26cf7c57d505fba9ca5a2d9cd2afd0728841c4..333076559040c4e864b666f1541462a62cbe9c85 100644 |
--- a/third_party/pkg/angular/test/core_dom/http_spec.dart |
+++ b/third_party/pkg/angular/test/core_dom/http_spec.dart |
@@ -28,148 +28,128 @@ class MockLocationWrapper implements LocationWrapper { |
get location => new MockLocation(url); |
} |
-main() => describe('http', () { |
- MockHttpBackend backend; |
- MockLocationWrapper locationWrapper; |
- |
- var cache; |
- |
- flush() { |
- microLeap(); |
- backend.flush(); |
- microLeap(); |
- } |
- |
- beforeEach(module((Module module) { |
- backend = new MockHttpBackend(); |
- locationWrapper = new MockLocationWrapper(); |
- cache = new FakeCache(); |
- module |
- ..value(HttpBackend, backend) |
- ..value(LocationWrapper, locationWrapper) |
- ..type(ExceptionHandler, implementedBy: LoggingExceptionHandler); |
- })); |
- |
- afterEach(inject((ExceptionHandler eh, Scope scope) { |
- scope.apply(); |
- backend.verifyNoOutstandingRequest(); |
- (eh as LoggingExceptionHandler).assertEmpty(); |
- })); |
- |
- describe('the instance', () { |
- Http http; |
- var callback; |
- |
- beforeEach(inject((Http h) { |
- http = h; |
- callback = jasmine.createSpy('callback'); |
- })); |
- |
- |
- it('should do basic request', async(() { |
- backend.expect('GET', '/url').respond(''); |
- http(url: '/url', method: 'GET'); |
- })); |
- |
- |
- it('should pass data if specified', async(() { |
- backend.expect('POST', '/url', 'some-data').respond(''); |
- http(url: '/url', method: 'POST', data: 'some-data'); |
- })); |
- |
- |
- it('should not pass data if not specificed', async(() { |
- // NOTE(deboer): I don't have a good why to test this since |
- // a null in backend.expect's data parameter means "undefined; |
- // we don't care about the data field. |
- backend.expect('POST', '/url', 'null').respond(''); |
- |
- http(url: '/url', method: 'POST'); |
- expect(() { |
- flush(); |
- }).toThrow('with different data'); |
- })); |
+void main() { |
+ describe('http', () { |
+ MockHttpBackend backend; |
+ MockLocationWrapper locationWrapper; |
+ |
+ var cache; |
+ |
+ flush() { |
+ microLeap(); |
+ backend.flush(); |
+ microLeap(); |
+ } |
+ |
+ beforeEachModule((Module module) { |
+ backend = new MockHttpBackend(); |
+ locationWrapper = new MockLocationWrapper(); |
+ cache = new FakeCache(); |
+ module |
+ ..value(HttpBackend, backend) |
+ ..value(LocationWrapper, locationWrapper) |
+ ..type(ExceptionHandler, implementedBy: LoggingExceptionHandler); |
+ }); |
+ afterEach((ExceptionHandler eh, Scope scope) { |
+ scope.apply(); |
+ backend.verifyNoOutstandingRequest(); |
+ backend.verifyNoOutstandingExpectation(); |
+ (eh as LoggingExceptionHandler).assertEmpty(); |
+ }); |
- describe('params', () { |
- it('should do basic request with params and encode', async(() { |
- backend.expect('GET', '/url?a%3D=%3F%26&b=2').respond(''); |
- http(url: '/url', params: {'a=':'?&', 'b':2}, method: 'GET'); |
- })); |
+ describe('the instance', () { |
+ Http http; |
+ var callback; |
+ beforeEach((Http h) { |
+ http = h; |
+ callback = jasmine.createSpy('callback'); |
+ }); |
- it('should merge params if url contains some already', async(() { |
- backend.expect('GET', '/url?c=3&a=1&b=2').respond(''); |
- http(url: '/url?c=3', params: {'a':1, 'b':2}, method: 'GET'); |
+ |
+ it('should do basic request', async(() { |
+ backend.expect('GET', '/url').respond(''); |
+ http(url: '/url', method: 'GET'); |
+ flush(); |
})); |
- it('should jsonify objects in params map', async(() { |
- backend.expect('GET', '/url?a=1&b=%7B%22c%22:3%7D').respond(''); |
- http(url: '/url', params: {'a':1, 'b':{'c':3}}, method: 'GET'); |
+ it('should pass data if specified', async(() { |
+ backend.expect('POST', '/url', 'some-data').respond(''); |
+ http(url: '/url', method: 'POST', data: 'some-data'); |
+ flush(); |
})); |
- it('should expand arrays in params map', async(() { |
- backend.expect('GET', '/url?a=1&a=2&a=3').respond(''); |
- http(url: '/url', params: {'a': [1,2,3]}, method: 'GET'); |
+ it('should not pass data if not specificed', async(() { |
+ // NOTE(deboer): I don't have a good why to test this since |
+ // a null in backend.expect's data parameter means "undefined; |
+ // we don't care about the data field. |
+ backend.expect('POST', '/url', 'null').respond(''); |
+ |
+ http(url: '/url', method: 'POST'); |
+ expect(() { |
+ flush(); |
+ }).toThrow('with different data'); |
+ |
+ // satisfy the expectation for our afterEach's assert. |
+ http(url: '/url', method: 'POST', data: 'null'); |
+ flush(); |
})); |
- it('should not encode @ in url params', async(() { |
- //encodeURIComponent is too agressive and doesn't follow http://www.ietf.org/rfc/rfc3986.txt |
- //with regards to the character set (pchar) allowed in path segments |
- //so we need this test to make sure that we don't over-encode the params and break stuff |
- //like buzz api which uses @self |
+ describe('params', () { |
+ it('should do basic request with params and encode', async(() { |
+ backend.expect('GET', '/url?a%3D=%3F%26&b=2').respond(''); |
+ http(url: '/url', params: {'a=':'?&', 'b':2}, method: 'GET'); |
+ flush(); |
+ })); |
- backend.expect('GET', r'/Path?!do%26h=g%3Da+h&:bar=$baz@1').respond(''); |
- http(url: '/Path', params: {':bar': r'$baz@1', '!do&h': 'g=a h'}, method: 'GET'); |
- })); |
- }); |
+ it('should merge params if url contains some already', async(() { |
+ backend.expect('GET', '/url?c=3&a=1&b=2').respond(''); |
+ http(url: '/url?c=3', params: {'a':1, 'b':2}, method: 'GET'); |
+ flush(); |
+ })); |
- describe('callbacks', () { |
- it('should pass in the response object when a request is successful', async(() { |
- backend.expect('GET', '/url').respond(207, 'my content', {'content-encoding': 'smurf'}); |
- http(url: '/url', method: 'GET').then((HttpResponse response) { |
- expect(response.data).toEqual('my content'); |
- expect(response.status).toEqual(207); |
- expect(response.headers()).toEqual({'content-encoding': 'smurf'}); |
- expect(response.config.url).toEqual('/url'); |
- callback(); |
- }); |
+ it('should jsonify objects in params map', async(() { |
+ backend.expect('GET', '/url?a=1&b=%7B%22c%22:3%7D').respond(''); |
+ http(url: '/url', params: {'a':1, 'b':{'c':3}}, method: 'GET'); |
+ flush(); |
+ })); |
- flush(); |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
+ it('should expand arrays in params map', async(() { |
+ backend.expect('GET', '/url?a=1&a=2&a=3').respond(''); |
+ http(url: '/url', params: {'a': [1,2,3]}, method: 'GET'); |
+ flush(); |
+ })); |
- it('should pass in the response object when a request failed', async(() { |
- backend.expect('GET', '/url').respond(543, 'bad error', {'request-id': '123'}); |
- http(url: '/url', method: 'GET').then((_) {}, onError: (response) { |
- expect(response.data).toEqual('bad error'); |
- expect(response.status).toEqual(543); |
- expect(response.headers()).toEqual({'request-id': '123'}); |
- expect(response.config.url).toEqual('/url'); |
- callback(); |
- }); |
+ it('should not encode @ in url params', async(() { |
+ //encodeURIComponent is too agressive and doesn't follow http://www.ietf.org/rfc/rfc3986.txt |
+ //with regards to the character set (pchar) allowed in path segments |
+ //so we need this test to make sure that we don't over-encode the params and break stuff |
+ //like buzz api which uses @self |
- flush(); |
+ backend.expect('GET', r'/Path?!do%26h=g%3Da+h&:bar=$baz@1').respond(''); |
+ http(url: '/Path', params: {':bar': r'$baz@1', '!do&h': 'g=a h'}, method: 'GET'); |
+ flush(); |
+ })); |
+ }); |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
+ describe('callbacks', () { |
- describe('success', () { |
- it('should allow http specific callbacks to be registered via "success"', async(() { |
+ it('should pass in the response object when a request is successful', async(() { |
backend.expect('GET', '/url').respond(207, 'my content', {'content-encoding': 'smurf'}); |
- http(url: '/url', method: 'GET').then((r) { |
- expect(r.data).toEqual('my content'); |
- expect(r.status).toEqual(207); |
- expect(r.headers()).toEqual({'content-encoding': 'smurf'}); |
- expect(r.config.url).toEqual('/url'); |
+ http(url: '/url', method: 'GET').then((HttpResponse response) { |
+ expect(response.data).toEqual('my content'); |
+ expect(response.status).toEqual(207); |
+ expect(response.headers()).toEqual({'content-encoding': 'smurf'}); |
+ expect(response.config.url).toEqual('/url'); |
callback(); |
}); |
@@ -177,18 +157,15 @@ main() => describe('http', () { |
expect(callback).toHaveBeenCalledOnce(); |
})); |
- }); |
- describe('error', () { |
- it('should allow http specific callbacks to be registered via "error"', async(() { |
+ it('should pass in the response object when a request failed', async(() { |
backend.expect('GET', '/url').respond(543, 'bad error', {'request-id': '123'}); |
- http(url: '/url', method: 'GET').then((_) {}, onError: (r) { |
- if (r is! HttpResponse) { throw r; } |
- expect(r.data).toEqual('bad error'); |
- expect(r.status).toEqual(543); |
- expect(r.headers()).toEqual({'request-id': '123'}); |
- expect(r.config.url).toEqual('/url'); |
+ http(url: '/url', method: 'GET').then((_) {}, onError: (response) { |
+ expect(response.data).toEqual('bad error'); |
+ expect(response.status).toEqual(543); |
+ expect(response.headers()).toEqual({'request-id': '123'}); |
+ expect(response.config.url).toEqual('/url'); |
callback(); |
}); |
@@ -196,1129 +173,1179 @@ main() => describe('http', () { |
expect(callback).toHaveBeenCalledOnce(); |
})); |
- }); |
- }); |
- describe('response headers', () { |
+ describe('success', () { |
+ it('should allow http specific callbacks to be registered via "success"', async(() { |
+ backend.expect('GET', '/url').respond(207, 'my content', {'content-encoding': 'smurf'}); |
+ http(url: '/url', method: 'GET').then((r) { |
+ expect(r.data).toEqual('my content'); |
+ expect(r.status).toEqual(207); |
+ expect(r.headers()).toEqual({'content-encoding': 'smurf'}); |
+ expect(r.config.url).toEqual('/url'); |
+ callback(); |
+ }); |
+ |
+ flush(); |
- it('should return single header', async(() { |
- backend.expect('GET', '/url').respond('', {'date': 'date-val'}); |
- callback.andCallFake((r) { |
- expect(r.headers('date')).toEqual('date-val'); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ })); |
}); |
- http(url: '/url', method: 'GET').then(callback); |
- flush(); |
- |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
+ describe('error', () { |
+ it('should allow http specific callbacks to be registered via "error"', async(() { |
+ backend.expect('GET', '/url').respond(543, 'bad error', {'request-id': '123'}); |
+ http(url: '/url', method: 'GET').then((_) {}, onError: (r) { |
+ if (r is! HttpResponse) { throw r; } |
+ expect(r.data).toEqual('bad error'); |
+ expect(r.status).toEqual(543); |
+ expect(r.headers()).toEqual({'request-id': '123'}); |
+ expect(r.config.url).toEqual('/url'); |
+ callback(); |
+ }); |
+ flush(); |
- it('should return null when single header does not exist', async(() { |
- backend.expect('GET', '/url').respond('', {'Some-Header': 'Fake'}); |
- callback.andCallFake((r) { |
- r.headers(); // we need that to get headers parsed first |
- expect(r.headers('nothing')).toEqual(null); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ })); |
}); |
+ }); |
- http(url: '/url', method: 'GET').then(callback); |
- flush(); |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
+ describe('response headers', () { |
+ it('should return single header', async(() { |
+ backend.expect('GET', '/url').respond('', {'date': 'date-val'}); |
+ callback.andCallFake((r) { |
+ expect(r.headers('date')).toEqual('date-val'); |
+ }); |
- it('should return all headers as object', async(() { |
- backend.expect('GET', '/url').respond('', { |
- 'content-encoding': 'gzip', |
- 'server': 'Apache' |
- }); |
+ http(url: '/url', method: 'GET').then(callback); |
- callback.andCallFake((r) { |
- expect(r.headers()).toEqual({'content-encoding': 'gzip', 'server': 'Apache'}); |
- }); |
+ flush(); |
- http(url: '/url', method: 'GET').then(callback); |
- flush(); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ })); |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
+ it('should return null when single header does not exist', async(() { |
+ backend.expect('GET', '/url').respond('', {'Some-Header': 'Fake'}); |
+ callback.andCallFake((r) { |
+ r.headers(); // we need that to get headers parsed first |
+ expect(r.headers('nothing')).toEqual(null); |
+ }); |
- it('should return empty object for jsonp request', async(() { |
- callback.andCallFake((r) { |
- expect(r.headers()).toEqual({}); |
- }); |
+ http(url: '/url', method: 'GET').then(callback); |
+ flush(); |
- backend.expect('JSONP', '/some').respond(200); |
- http(url: '/some', method: 'JSONP').then(callback); |
- flush(); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ })); |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
- }); |
+ it('should return all headers as object', async(() { |
+ backend.expect('GET', '/url').respond('', { |
+ 'content-encoding': 'gzip', |
+ 'server': 'Apache' |
+ }); |
- describe('response headers parser', () { |
- parseHeaders(x) => Http.parseHeaders(new MockHttpRequest(null, null, x)); |
- |
- it('should parse basic', () { |
- var parsed = parseHeaders( |
- 'date: Thu, 04 Aug 2011 20:23:08 GMT\n' + |
- 'content-encoding: gzip\n' + |
- 'transfer-encoding: chunked\n' + |
- 'x-cache-info: not cacheable; response has already expired, not cacheable; response has already expired\n' + |
- 'connection: Keep-Alive\n' + |
- 'x-backend-server: pm-dekiwiki03\n' + |
- 'pragma: no-cache\n' + |
- 'server: Apache\n' + |
- 'x-frame-options: DENY\n' + |
- 'content-type: text/html; charset=utf-8\n' + |
- 'vary: Cookie, Accept-Encoding\n' + |
- 'keep-alive: timeout=5, max=1000\n' + |
- 'expires: Thu: , 19 Nov 1981 08:52:00 GMT\n'); |
- |
- expect(parsed['date']).toEqual('Thu, 04 Aug 2011 20:23:08 GMT'); |
- expect(parsed['content-encoding']).toEqual('gzip'); |
- expect(parsed['transfer-encoding']).toEqual('chunked'); |
- expect(parsed['keep-alive']).toEqual('timeout=5, max=1000'); |
- }); |
+ callback.andCallFake((r) { |
+ expect(r.headers()).toEqual({'content-encoding': 'gzip', 'server': 'Apache'}); |
+ }); |
+ http(url: '/url', method: 'GET').then(callback); |
+ flush(); |
- it('should parse lines without space after colon', () { |
- expect(parseHeaders('key:value')['key']).toEqual('value'); |
- }); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ })); |
- it('should trim the values', () { |
- expect(parseHeaders('key: value ')['key']).toEqual('value'); |
- }); |
+ it('should return empty object for jsonp request', async(() { |
+ callback.andCallFake((r) { |
+ expect(r.headers()).toEqual({}); |
+ }); |
+ backend.expect('JSONP', '/some').respond(200); |
+ http(url: '/some', method: 'JSONP').then(callback); |
+ flush(); |
- it('should allow headers without value', () { |
- expect(parseHeaders('key:')['key']).toEqual(''); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ })); |
}); |
- it('should merge headers with same key', () { |
- expect(parseHeaders('key: a\nkey:b\n')['key']).toEqual('a, b'); |
- }); |
+ describe('response headers parser', () { |
+ parseHeaders(x) => Http.parseHeaders(new MockHttpRequest(null, null, x)); |
+ |
+ it('should parse basic', () { |
+ var parsed = parseHeaders( |
+ 'date: Thu, 04 Aug 2011 20:23:08 GMT\n' + |
+ 'content-encoding: gzip\n' + |
+ 'transfer-encoding: chunked\n' + |
+ 'x-cache-info: not cacheable; response has already expired, not cacheable; response has already expired\n' + |
+ 'connection: Keep-Alive\n' + |
+ 'x-backend-server: pm-dekiwiki03\n' + |
+ 'pragma: no-cache\n' + |
+ 'server: Apache\n' + |
+ 'x-frame-options: DENY\n' + |
+ 'content-type: text/html; charset=utf-8\n' + |
+ 'vary: Cookie, Accept-Encoding\n' + |
+ 'keep-alive: timeout=5, max=1000\n' + |
+ 'expires: Thu: , 19 Nov 1981 08:52:00 GMT\n'); |
+ |
+ expect(parsed['date']).toEqual('Thu, 04 Aug 2011 20:23:08 GMT'); |
+ expect(parsed['content-encoding']).toEqual('gzip'); |
+ expect(parsed['transfer-encoding']).toEqual('chunked'); |
+ expect(parsed['keep-alive']).toEqual('timeout=5, max=1000'); |
+ }); |
- it('should normalize keys to lower case', () { |
- expect(parseHeaders('KeY: value')['key']).toEqual('value'); |
- }); |
+ it('should parse lines without space after colon', () { |
+ expect(parseHeaders('key:value')['key']).toEqual('value'); |
+ }); |
- it('should parse CRLF as delimiter', () { |
- // IE does use CRLF |
- expect(parseHeaders('a: b\r\nc: d\r\n')).toEqual({'a': 'b', 'c': 'd'}); |
- expect(parseHeaders('a: b\r\nc: d\r\n')['a']).toEqual('b'); |
- }); |
+ it('should trim the values', () { |
+ expect(parseHeaders('key: value ')['key']).toEqual('value'); |
+ }); |
- it('should parse tab after semi-colon', () { |
- expect(parseHeaders('a:\tbb')['a']).toEqual('bb'); |
- expect(parseHeaders('a: \tbb')['a']).toEqual('bb'); |
- }); |
- }); |
+ it('should allow headers without value', () { |
+ expect(parseHeaders('key:')['key']).toEqual(''); |
+ }); |
- describe('request headers', () { |
+ it('should merge headers with same key', () { |
+ expect(parseHeaders('key: a\nkey:b\n')['key']).toEqual('a, b'); |
+ }); |
- it('should send custom headers', async(() { |
- backend.expect('GET', '/url', null, (headers) { |
- return headers['Custom'] == 'header'; |
- }).respond(''); |
- http(url: '/url', method: 'GET', headers: { |
- 'Custom': 'header', |
+ it('should normalize keys to lower case', () { |
+ expect(parseHeaders('KeY: value')['key']).toEqual('value'); |
}); |
- flush(); |
- })); |
+ it('should parse CRLF as delimiter', () { |
+ // IE does use CRLF |
+ expect(parseHeaders('a: b\r\nc: d\r\n')).toEqual({'a': 'b', 'c': 'd'}); |
+ expect(parseHeaders('a: b\r\nc: d\r\n')['a']).toEqual('b'); |
+ }); |
- it('should set default headers for GET request', async(() { |
- backend.expect('GET', '/url', null, (headers) { |
- return headers['Accept'] == 'application/json, text/plain, */*'; |
- }).respond(''); |
- http(url: '/url', method: 'GET', headers: {}); |
- flush(); |
- })); |
+ it('should parse tab after semi-colon', () { |
+ expect(parseHeaders('a:\tbb')['a']).toEqual('bb'); |
+ expect(parseHeaders('a: \tbb')['a']).toEqual('bb'); |
+ }); |
+ }); |
- it('should set default headers for POST request', async(() { |
- backend.expect('POST', '/url', 'messageBody', (headers) { |
- return headers['Accept'] == 'application/json, text/plain, */*' && |
- headers['Content-Type'] == 'application/json;charset=utf-8'; |
- }).respond(''); |
+ describe('request headers', () { |
- http(url: '/url', method: 'POST', headers: {}, data: 'messageBody'); |
- flush(); |
- })); |
+ it('should send custom headers', async(() { |
+ backend.expect('GET', '/url', null, (headers) { |
+ return headers['Custom'] == 'header'; |
+ }).respond(''); |
+ http(url: '/url', method: 'GET', headers: { |
+ 'Custom': 'header', |
+ }); |
- it('should set default headers for PUT request', async(() { |
- backend.expect('PUT', '/url', 'messageBody', (headers) { |
- return headers['Accept'] == 'application/json, text/plain, */*' && |
- headers['Content-Type'] == 'application/json;charset=utf-8'; |
- }).respond(''); |
+ flush(); |
+ })); |
- http(url: '/url', method: 'PUT', headers: {}, data: 'messageBody'); |
- flush(); |
- })); |
- it('should set default headers for PATCH request', async(() { |
- backend.expect('PATCH', '/url', 'messageBody', (headers) { |
- return headers['Accept'] == 'application/json, text/plain, */*' && |
- headers['Content-Type'] == 'application/json;charset=utf-8'; |
- }).respond(''); |
+ it('should set default headers for GET request', async(() { |
+ backend.expect('GET', '/url', null, (headers) { |
+ return headers['Accept'] == 'application/json, text/plain, */*'; |
+ }).respond(''); |
- http(url: '/url', method: 'PATCH', headers: {}, data: 'messageBody'); |
- flush(); |
- })); |
+ http(url: '/url', method: 'GET', headers: {}); |
+ flush(); |
+ })); |
- it('should set default headers for custom HTTP method', async(() { |
- backend.expect('FOO', '/url', null, (headers) { |
- return headers['Accept'] == 'application/json, text/plain, */*'; |
- }).respond(''); |
- http(url: '/url', method: 'FOO', headers: {}); |
- flush(); |
- })); |
+ it('should set default headers for POST request', async(() { |
+ backend.expect('POST', '/url', 'messageBody', (headers) { |
+ return headers['Accept'] == 'application/json, text/plain, */*' && |
+ headers['Content-Type'] == 'application/json;charset=utf-8'; |
+ }).respond(''); |
+ http(url: '/url', method: 'POST', headers: {}, data: 'messageBody'); |
+ flush(); |
+ })); |
- it('should override default headers with custom', async(() { |
- backend.expect('POST', '/url', 'messageBody', (headers) { |
- return headers['Accept'] == 'Rewritten' && |
- headers['Content-Type'] == 'Rewritten'; |
- }).respond(''); |
- http(url: '/url', method: 'POST', data: 'messageBody', headers: { |
- 'Accept': 'Rewritten', |
- 'Content-Type': 'Rewritten' |
- }); |
- flush(); |
- })); |
+ it('should set default headers for PUT request', async(() { |
+ backend.expect('PUT', '/url', 'messageBody', (headers) { |
+ return headers['Accept'] == 'application/json, text/plain, */*' && |
+ headers['Content-Type'] == 'application/json;charset=utf-8'; |
+ }).respond(''); |
- it('should override default headers with custom in a case insensitive manner', async(() { |
- backend.expect('POST', '/url', 'messageBody', (headers) { |
- return headers['accept'] == 'Rewritten' && |
- headers['content-type'] == 'Content-Type Rewritten' && |
- headers['Accept'] == null && |
- headers['Content-Type'] == null; |
- }).respond(''); |
- |
- http(url: '/url', method: 'POST', data: 'messageBody', headers: { |
- 'accept': 'Rewritten', |
- 'content-type': 'Content-Type Rewritten' |
- }); |
- flush(); |
- })); |
+ http(url: '/url', method: 'PUT', headers: {}, data: 'messageBody'); |
+ flush(); |
+ })); |
- it('should not set XSRF cookie for cross-domain requests', async(inject((BrowserCookies cookies) { |
- cookies['XSRF-TOKEN'] = 'secret'; |
- locationWrapper.url = 'http://host.com/base'; |
- backend.expect('GET', 'http://www.test.com/url', null, (headers) { |
- return headers['X-XSRF-TOKEN'] == null; |
- }).respond(''); |
+ it('should set default headers for PATCH request', async(() { |
+ backend.expect('PATCH', '/url', 'messageBody', (headers) { |
+ return headers['Accept'] == 'application/json, text/plain, */*' && |
+ headers['Content-Type'] == 'application/json;charset=utf-8'; |
+ }).respond(''); |
- http(url: 'http://www.test.com/url', method: 'GET', headers: {}); |
- flush(); |
- }))); |
+ http(url: '/url', method: 'PATCH', headers: {}, data: 'messageBody'); |
+ flush(); |
+ })); |
+ it('should set default headers for custom HTTP method', async(() { |
+ backend.expect('FOO', '/url', null, (headers) { |
+ return headers['Accept'] == 'application/json, text/plain, */*'; |
+ }).respond(''); |
- it('should not send Content-Type header if request data/body is null', async(() { |
- backend.expect('POST', '/url', null, (headers) { |
- return !headers.containsKey('Content-Type'); |
- }).respond(''); |
+ http(url: '/url', method: 'FOO', headers: {}); |
+ flush(); |
+ })); |
- backend.expect('POST', '/url2', null, (headers) { |
- return !headers.containsKey('content-type'); |
- }).respond(''); |
- http(url: '/url', method: 'POST'); |
- http(url: '/url2', method: 'POST', headers: {'content-type': 'Rewritten'}); |
- flush(); |
- })); |
+ it('should override default headers with custom', async(() { |
+ backend.expect('POST', '/url', 'messageBody', (headers) { |
+ return headers['Accept'] == 'Rewritten' && |
+ headers['Content-Type'] == 'Rewritten'; |
+ }).respond(''); |
+ http(url: '/url', method: 'POST', data: 'messageBody', headers: { |
+ 'Accept': 'Rewritten', |
+ 'Content-Type': 'Rewritten' |
+ }); |
+ flush(); |
+ })); |
- it('should set the XSRF cookie into a XSRF header', async(inject((BrowserCookies cookies) { |
- checkXSRF(secret, [header]) { |
- return (headers) { |
- return headers[header != null ? header : 'X-XSRF-TOKEN'] == secret; |
- }; |
- } |
+ it('should override default headers with custom in a case insensitive manner', async(() { |
+ backend.expect('POST', '/url', 'messageBody', (headers) { |
+ return headers['accept'] == 'Rewritten' && |
+ headers['content-type'] == 'Content-Type Rewritten' && |
+ headers['Accept'] == null && |
+ headers['Content-Type'] == null; |
+ }).respond(''); |
+ |
+ http(url: '/url', method: 'POST', data: 'messageBody', headers: { |
+ 'accept': 'Rewritten', |
+ 'content-type': 'Content-Type Rewritten' |
+ }); |
+ flush(); |
+ })); |
- cookies['XSRF-TOKEN'] = 'secret'; |
- cookies['aCookie'] = 'secret2'; |
- backend.expect('GET', '/url', null, checkXSRF('secret')).respond(''); |
- backend.expect('POST', '/url', null, checkXSRF('secret')).respond(''); |
- backend.expect('PUT', '/url', null, checkXSRF('secret')).respond(''); |
- backend.expect('DELETE', '/url', null, checkXSRF('secret')).respond(''); |
- backend.expect('GET', '/url', null, checkXSRF('secret', 'aHeader')).respond(''); |
- backend.expect('GET', '/url', null, checkXSRF('secret2')).respond(''); |
+ it('should not set XSRF cookie for cross-domain requests', async((BrowserCookies cookies) { |
+ cookies['XSRF-TOKEN'] = 'secret'; |
+ locationWrapper.url = 'http://host.com/base'; |
+ backend.expect('GET', 'http://www.test.com/url', null, (headers) { |
+ return headers['X-XSRF-TOKEN'] == null; |
+ }).respond(''); |
- http(url: '/url', method: 'GET'); |
- http(url: '/url', method: 'POST', headers: {'S-ome': 'Header'}); |
- http(url: '/url', method: 'PUT', headers: {'Another': 'Header'}); |
- http(url: '/url', method: 'DELETE', headers: {}); |
- http(url: '/url', method: 'GET', xsrfHeaderName: 'aHeader'); |
- http(url: '/url', method: 'GET', xsrfCookieName: 'aCookie'); |
+ http(url: 'http://www.test.com/url', method: 'GET', headers: {}); |
+ flush(); |
+ })); |
- flush(); |
- }))); |
- it('should send execute result if header value is function', async(() { |
- var headerConfig = {'Accept': () { return 'Rewritten'; }}; |
+ it('should not send Content-Type header if request data/body is null', async(() { |
+ backend.expect('POST', '/url', null, (headers) { |
+ return !headers.containsKey('Content-Type'); |
+ }).respond(''); |
- checkHeaders(headers) { |
- return headers['Accept'] == 'Rewritten'; |
- } |
+ backend.expect('POST', '/url2', null, (headers) { |
+ return !headers.containsKey('content-type'); |
+ }).respond(''); |
- backend.expect('GET', '/url', null, checkHeaders).respond(''); |
- backend.expect('POST', '/url', null, checkHeaders).respond(''); |
- backend.expect('PUT', '/url', null, checkHeaders).respond(''); |
- backend.expect('PATCH', '/url', null, checkHeaders).respond(''); |
- backend.expect('DELETE', '/url', null, checkHeaders).respond(''); |
+ http(url: '/url', method: 'POST'); |
+ http(url: '/url2', method: 'POST', headers: {'content-type': 'Rewritten'}); |
+ flush(); |
+ })); |
- http(url: '/url', method: 'GET', headers: headerConfig); |
- http(url: '/url', method: 'POST', headers: headerConfig); |
- http(url: '/url', method: 'PUT', headers: headerConfig); |
- http(url: '/url', method: 'PATCH', headers: headerConfig); |
- http(url: '/url', method: 'DELETE', headers: headerConfig); |
- flush(); |
- })); |
- }); |
+ it('should set the XSRF cookie into a XSRF header', async((BrowserCookies cookies) { |
+ checkXSRF(secret, [header]) { |
+ return (headers) { |
+ return headers[header != null ? header : 'X-XSRF-TOKEN'] == secret; |
+ }; |
+ } |
+ |
+ cookies['XSRF-TOKEN'] = 'secret'; |
+ cookies['aCookie'] = 'secret2'; |
+ backend.expect('GET', '/url', null, checkXSRF('secret')).respond(''); |
+ backend.expect('POST', '/url', null, checkXSRF('secret')).respond(''); |
+ backend.expect('PUT', '/url', null, checkXSRF('secret')).respond(''); |
+ backend.expect('DELETE', '/url', null, checkXSRF('secret')).respond(''); |
+ backend.expect('GET', '/url', null, checkXSRF('secret', 'aHeader')).respond(''); |
+ backend.expect('GET', '/url', null, checkXSRF('secret2')).respond(''); |
+ |
+ http(url: '/url', method: 'GET'); |
+ http(url: '/url', method: 'POST', headers: {'S-ome': 'Header'}); |
+ http(url: '/url', method: 'PUT', headers: {'Another': 'Header'}); |
+ http(url: '/url', method: 'DELETE', headers: {}); |
+ http(url: '/url', method: 'GET', xsrfHeaderName: 'aHeader'); |
+ http(url: '/url', method: 'GET', xsrfCookieName: 'aCookie'); |
+ flush(); |
+ })); |
- describe('short methods', () { |
+ it('should send execute result if header value is function', async(() { |
+ var headerConfig = {'Accept': () { return 'Rewritten'; }}; |
- checkHeader(name, value) { |
- return (headers) { |
- return headers[name] == value; |
- }; |
- } |
+ checkHeaders(headers) { |
+ return headers['Accept'] == 'Rewritten'; |
+ } |
- it('should have get()', async(() { |
- backend.expect('GET', '/url').respond(''); |
- http.get('/url'); |
- })); |
+ backend.expect('GET', '/url', null, checkHeaders).respond(''); |
+ backend.expect('POST', '/url', null, checkHeaders).respond(''); |
+ backend.expect('PUT', '/url', null, checkHeaders).respond(''); |
+ backend.expect('PATCH', '/url', null, checkHeaders).respond(''); |
+ backend.expect('DELETE', '/url', null, checkHeaders).respond(''); |
+ http(url: '/url', method: 'GET', headers: headerConfig); |
+ http(url: '/url', method: 'POST', headers: headerConfig); |
+ http(url: '/url', method: 'PUT', headers: headerConfig); |
+ http(url: '/url', method: 'PATCH', headers: headerConfig); |
+ http(url: '/url', method: 'DELETE', headers: headerConfig); |
- it('get() should allow config param', async(() { |
- backend.expect('GET', '/url', null, checkHeader('Custom', 'Header')).respond(''); |
- http.get('/url', headers: {'Custom': 'Header'}); |
- })); |
+ flush(); |
+ })); |
+ }); |
- it('should have delete()', async(() { |
- backend.expect('DELETE', '/url').respond(''); |
- http.delete('/url'); |
- })); |
+ describe('short methods', () { |
+ checkHeader(name, value) { |
+ return (headers) { |
+ return headers[name] == value; |
+ }; |
+ } |
- it('delete() should allow config param', async(() { |
- backend.expect('DELETE', '/url', null, checkHeader('Custom', 'Header')).respond(''); |
- http.delete('/url', headers: {'Custom': 'Header'}); |
- })); |
+ it('should have get()', async(() { |
+ backend.expect('GET', '/url').respond(''); |
+ http.get('/url'); |
+ flush(); |
+ })); |
- it('should have head()', async(() { |
- backend.expect('HEAD', '/url').respond(''); |
- http.head('/url'); |
- })); |
+ it('get() should allow config param', async(() { |
+ backend.expect('GET', '/url', null, checkHeader('Custom', 'Header')).respond(''); |
+ http.get('/url', headers: {'Custom': 'Header'}); |
+ flush(); |
+ })); |
- it('head() should allow config param', async(() { |
- backend.expect('HEAD', '/url', null, checkHeader('Custom', 'Header')).respond(''); |
- http.head('/url', headers: {'Custom': 'Header'}); |
- })); |
+ it('should have delete()', async(() { |
+ backend.expect('DELETE', '/url').respond(''); |
+ http.delete('/url'); |
+ flush(); |
+ })); |
- it('should have post()', async(() { |
- backend.expect('POST', '/url', 'some-data').respond(''); |
- http.post('/url', 'some-data'); |
- })); |
+ it('delete() should allow config param', async(() { |
+ backend.expect('DELETE', '/url', null, checkHeader('Custom', 'Header')).respond(''); |
+ http.delete('/url', headers: {'Custom': 'Header'}); |
+ flush(); |
+ })); |
- it('post() should allow config param', async(() { |
- backend.expect('POST', '/url', 'some-data', checkHeader('Custom', 'Header')).respond(''); |
- http.post('/url', 'some-data', headers: {'Custom': 'Header'}); |
- })); |
+ it('should have head()', async(() { |
+ backend.expect('HEAD', '/url').respond(''); |
+ http.head('/url'); |
+ flush(); |
+ })); |
- it('should have put()', async(() { |
- backend.expect('PUT', '/url', 'some-data').respond(''); |
- http.put('/url', 'some-data'); |
- })); |
+ it('head() should allow config param', async(() { |
+ backend.expect('HEAD', '/url', null, checkHeader('Custom', 'Header')).respond(''); |
+ http.head('/url', headers: {'Custom': 'Header'}); |
+ flush(); |
+ })); |
- it('put() should allow config param', async(() { |
- backend.expect('PUT', '/url', 'some-data', checkHeader('Custom', 'Header')).respond(''); |
- http.put('/url', 'some-data', headers: {'Custom': 'Header'}); |
- })); |
+ it('should have post()', async(() { |
+ backend.expect('POST', '/url', 'some-data').respond(''); |
+ http.post('/url', 'some-data'); |
+ flush(); |
+ })); |
- it('should have jsonp()', async(() { |
- backend.expect('JSONP', '/url').respond(''); |
- http.jsonp('/url'); |
- })); |
+ it('post() should allow config param', async(() { |
+ backend.expect('POST', '/url', 'some-data', checkHeader('Custom', 'Header')).respond(''); |
+ http.post('/url', 'some-data', headers: {'Custom': 'Header'}); |
+ flush(); |
+ })); |
- it('jsonp() should allow config param', async(() { |
- backend.expect('JSONP', '/url', null, checkHeader('Custom', 'Header')).respond(''); |
- http.jsonp('/url', headers: {'Custom': 'Header'}); |
- })); |
- }); |
+ it('should have put()', async(() { |
+ backend.expect('PUT', '/url', 'some-data').respond(''); |
+ http.put('/url', 'some-data'); |
+ flush(); |
+ })); |
- describe('cache', () { |
+ it('put() should allow config param', async(() { |
+ backend.expect('PUT', '/url', 'some-data', checkHeader('Custom', 'Header')).respond(''); |
+ http.put('/url', 'some-data', headers: {'Custom': 'Header'}); |
+ flush(); |
+ })); |
- Cache cache; |
- beforeEach((() { |
- cache = new UnboundedCache(); |
- })); |
+ it('should have jsonp()', async(() { |
+ backend.expect('JSONP', '/url').respond(''); |
+ http.jsonp('/url'); |
+ flush(); |
+ })); |
- doFirstCacheRequest([String method, int respStatus, Map headers]) { |
- backend.expect(method != null ? method :'GET', '/url') |
- .respond(respStatus != null ? respStatus : 200, 'content', headers); |
- http(method: method != null ? method : 'GET', url: '/url', cache: cache) |
- .then((_){}, onError: (_){}); |
- flush(); |
- } |
+ it('jsonp() should allow config param', async(() { |
+ backend.expect('JSONP', '/url', null, checkHeader('Custom', 'Header')).respond(''); |
+ http.jsonp('/url', headers: {'Custom': 'Header'}); |
+ flush(); |
+ })); |
+ }); |
- it('should cache GET request when cache is provided', async(() { |
- doFirstCacheRequest(); |
+ describe('cache', () { |
- http(method: 'get', url: '/url', cache: cache).then(callback); |
+ Cache cache; |
- microLeap(); |
+ beforeEach((() { |
+ cache = new UnboundedCache(); |
+ })); |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual('content'); |
- })); |
+ doFirstCacheRequest([String method, int respStatus, Map headers]) { |
+ backend.expect(method != null ? method :'GET', '/url') |
+ .respond(respStatus != null ? respStatus : 200, 'content', headers); |
+ http(method: method != null ? method : 'GET', url: '/url', cache: cache) |
+ .then((_){}, onError: (_){}); |
+ flush(); |
+ } |
- it('should not cache when cache is not provided', async(() { |
- doFirstCacheRequest(); |
- backend.expect('GET', '/url').respond(); |
- http(method: 'GET', url: '/url'); |
- microLeap(); |
- })); |
+ it('should cache GET request when cache is provided', async(() { |
+ doFirstCacheRequest(); |
+ http(method: 'get', url: '/url', cache: cache).then(callback); |
- it('should perform request when cache cleared', async(() { |
- doFirstCacheRequest(); |
+ microLeap(); |
- cache.removeAll(); |
- backend.expect('GET', '/url').respond(); |
- http(method: 'GET', url: '/url', cache: cache); |
- microLeap(); |
- })); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual('content'); |
+ })); |
- it('should not cache POST request', async(() { |
- doFirstCacheRequest('POST'); |
+ it('should not cache when cache is not provided', async(() { |
+ doFirstCacheRequest(); |
- backend.expect('POST', '/url').respond('content2'); |
- http(method: 'POST', url: '/url', cache: cache).then(callback); |
- flush(); |
+ backend.expect('GET', '/url').respond(); |
+ http(method: 'GET', url: '/url'); |
+ flush(); |
+ })); |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual('content2'); |
- })); |
+ it('should perform request when cache cleared', async(() { |
+ doFirstCacheRequest(); |
- it('should not cache PUT request', async(() { |
- doFirstCacheRequest('PUT'); |
+ cache.removeAll(); |
+ backend.expect('GET', '/url').respond(); |
+ http(method: 'GET', url: '/url', cache: cache); |
+ flush(); |
+ })); |
- backend.expect('PUT', '/url').respond('content2'); |
- http(method: 'PUT', url: '/url', cache: cache).then(callback); |
- flush(); |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual('content2'); |
- })); |
+ it('should not cache POST request', async(() { |
+ doFirstCacheRequest('POST'); |
+ backend.expect('POST', '/url').respond('content2'); |
+ http(method: 'POST', url: '/url', cache: cache).then(callback); |
+ flush(); |
- it('should not cache DELETE request', async(() { |
- doFirstCacheRequest('DELETE'); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual('content2'); |
+ })); |
- backend.expect('DELETE', '/url').respond(206); |
- http(method: 'DELETE', url: '/url', cache: cache).then(callback); |
- flush(); |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
+ it('should not cache PUT request', async(() { |
+ doFirstCacheRequest('PUT'); |
+ backend.expect('PUT', '/url').respond('content2'); |
+ http(method: 'PUT', url: '/url', cache: cache).then(callback); |
+ flush(); |
- it('should not cache non 2xx responses', async(() { |
- doFirstCacheRequest('GET', 404); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual('content2'); |
+ })); |
- backend.expect('GET', '/url').respond('content2'); |
- http(method: 'GET', url: '/url', cache: cache).then(callback); |
- flush(); |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual('content2'); |
- })); |
+ it('should not cache DELETE request', async(() { |
+ doFirstCacheRequest('DELETE'); |
+ backend.expect('DELETE', '/url').respond(206); |
+ http(method: 'DELETE', url: '/url', cache: cache).then(callback); |
+ flush(); |
- it('should cache the headers as well', async(() { |
- doFirstCacheRequest('GET', 200, {'content-encoding': 'gzip', 'server': 'Apache'}); |
- callback.andCallFake((r) { |
- expect(r.headers()).toEqual({'content-encoding': 'gzip', 'server': 'Apache'}); |
- expect(r.headers('server')).toEqual('Apache'); |
- }); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ })); |
- http(method: 'GET', url: '/url', cache: cache).then(callback); |
- microLeap(); |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
+ it('should not cache non 2xx responses', async(() { |
+ doFirstCacheRequest('GET', 404); |
+ backend.expect('GET', '/url').respond('content2'); |
+ http(method: 'GET', url: '/url', cache: cache).then(callback); |
+ flush(); |
- it('should not share the cached headers object instance', async(() { |
- doFirstCacheRequest('GET', 200, {'content-encoding': 'gzip', 'server': 'Apache'}); |
- callback.andCallFake((r) { |
- expect(r.headers()).toEqual(cache.get('/url').headers()); |
- expect(r.headers()).not.toBe(cache.get('/url').headers()); |
- }); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual('content2'); |
+ })); |
- http(method: 'GET', url: '/url', cache: cache).then(callback); |
- microLeap(); |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
+ it('should cache the headers as well', async(() { |
+ doFirstCacheRequest('GET', 200, {'content-encoding': 'gzip', 'server': 'Apache'}); |
+ callback.andCallFake((r) { |
+ expect(r.headers()).toEqual({'content-encoding': 'gzip', 'server': 'Apache'}); |
+ expect(r.headers('server')).toEqual('Apache'); |
+ }); |
+ http(method: 'GET', url: '/url', cache: cache).then(callback); |
+ microLeap(); |
- it('should cache status code as well', async(() { |
- doFirstCacheRequest('GET', 201); |
- callback.andCallFake((r) { |
- expect(r.status).toEqual(201); |
- }); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ })); |
- http(method: 'get', url: '/url', cache: cache).then(callback); |
- microLeap(); |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
+ it('should not share the cached headers object instance', async(() { |
+ doFirstCacheRequest('GET', 200, {'content-encoding': 'gzip', 'server': 'Apache'}); |
+ callback.andCallFake((r) { |
+ expect(r.headers()).toEqual(cache.get('/url').headers()); |
+ expect(r.headers()).not.toBe(cache.get('/url').headers()); |
+ }); |
+ http(method: 'GET', url: '/url', cache: cache).then(callback); |
+ microLeap(); |
- it('should use cache even if second request was made before the first returned', async(() { |
- backend.expect('GET', '/url').respond(201, 'fake-response'); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ })); |
- callback.andCallFake((r) { |
- expect(r.data).toEqual('fake-response'); |
- expect(r.status).toEqual(201); |
- }); |
- http(method: 'GET', url: '/url', cache: cache).then(callback); |
- http(method: 'GET', url: '/url', cache: cache).then(callback); |
+ it('should cache status code as well', async(() { |
+ doFirstCacheRequest('GET', 201); |
+ callback.andCallFake((r) { |
+ expect(r.status).toEqual(201); |
+ }); |
- flush(); |
+ http(method: 'get', url: '/url', cache: cache).then(callback); |
+ microLeap(); |
- expect(callback).toHaveBeenCalled(); |
- expect(callback.callCount).toEqual(2); |
- })); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ })); |
- describe('http.defaults.cache', () { |
+ it('should use cache even if second request was made before the first returned', async(() { |
+ backend.expect('GET', '/url').respond(201, 'fake-response'); |
- it('should be null by default', () { |
- expect(http.defaults.cache).toBeNull(); |
- }); |
+ callback.andCallFake((r) { |
+ expect(r.data).toEqual('fake-response'); |
+ expect(r.status).toEqual(201); |
+ }); |
- it('should cache requests when no cache given in request config', async(() { |
- http.defaults.cache = cache; |
+ http(method: 'GET', url: '/url', cache: cache).then(callback); |
+ http(method: 'GET', url: '/url', cache: cache).then(callback); |
- // First request fills the cache from server response. |
- backend.expect('GET', '/url').respond(200, 'content'); |
- http(method: 'GET', url: '/url'); // Notice no cache given in config. |
flush(); |
- // Second should be served from cache, without sending request to server. |
- http(method: 'get', url: '/url').then(callback); |
- microLeap(); |
+ expect(callback).toHaveBeenCalled(); |
+ expect(callback.callCount).toEqual(2); |
+ })); |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual('content'); |
- // Invalidate cache entry. |
- http.defaults.cache.remove("/url"); |
+ describe('http.defaults.cache', () { |
- // After cache entry removed, a request should be sent to server. |
- backend.expect('GET', '/url').respond(200, 'content'); |
- http(method: 'GET', url: '/url'); |
- flush(); |
- })); |
+ it('should be null by default', () { |
+ expect(http.defaults.cache).toBeNull(); |
+ }); |
- it('should have less priority than explicitly given cache', async(() { |
- var localCache = new UnboundedCache(); |
- http.defaults.cache = cache; |
+ it('should cache requests when no cache given in request config', async(() { |
+ http.defaults.cache = cache; |
- // Fill local cache. |
- backend.expect('GET', '/url').respond(200, 'content-local-cache'); |
- http(method: 'GET', url: '/url', cache: localCache); |
- flush(); |
+ // First request fills the cache from server response. |
+ backend.expect('GET', '/url').respond(200, 'content'); |
+ http(method: 'GET', url: '/url'); // Notice no cache given in config. |
+ flush(); |
- // Fill default cache. |
- backend.expect('GET', '/url').respond(200, 'content-default-cache'); |
- http(method: 'GET', url: '/url'); |
- flush(); |
+ // Second should be served from cache, without sending request to server. |
+ http(method: 'get', url: '/url').then(callback); |
+ microLeap(); |
- // Serve request from default cache when no local given. |
- http(method: 'get', url: '/url').then(callback); |
- microLeap(); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual('content'); |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual('content-default-cache'); |
- callback.reset(); |
+ // Invalidate cache entry. |
+ http.defaults.cache.remove("/url"); |
- // Serve request from local cache when it is given (but default filled too). |
- http(method: 'get', url: '/url', cache: localCache).then(callback); |
- microLeap(); |
+ // After cache entry removed, a request should be sent to server. |
+ backend.expect('GET', '/url').respond(200, 'content'); |
+ http(method: 'GET', url: '/url'); |
+ flush(); |
+ })); |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual('content-local-cache'); |
- })); |
+ it('should have less priority than explicitly given cache', async(() { |
+ var localCache = new UnboundedCache(); |
+ http.defaults.cache = cache; |
- it('should be skipped if {cache: false} is passed in request config', async(() { |
- http.defaults.cache = cache; |
+ // Fill local cache. |
+ backend.expect('GET', '/url').respond(200, 'content-local-cache'); |
+ http(method: 'GET', url: '/url', cache: localCache); |
+ flush(); |
- backend.expect('GET', '/url').respond(200, 'content'); |
- http(method: 'GET', url: '/url'); |
- flush(); |
+ // Fill default cache. |
+ backend.expect('GET', '/url').respond(200, 'content-default-cache'); |
+ http(method: 'GET', url: '/url'); |
+ flush(); |
- backend.expect('GET', '/url').respond(); |
- http(method: 'GET', url: '/url', cache: false); |
- flush(); |
- })); |
+ // Serve request from default cache when no local given. |
+ http(method: 'get', url: '/url').then(callback); |
+ microLeap(); |
+ |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual('content-default-cache'); |
+ callback.reset(); |
+ |
+ // Serve request from local cache when it is given (but default filled too). |
+ http(method: 'get', url: '/url', cache: localCache).then(callback); |
+ microLeap(); |
+ |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual('content-local-cache'); |
+ })); |
+ |
+ it('should be skipped if {cache: false} is passed in request config', async(() { |
+ http.defaults.cache = cache; |
+ |
+ backend.expect('GET', '/url').respond(200, 'content'); |
+ http(method: 'GET', url: '/url'); |
+ flush(); |
+ |
+ backend.expect('GET', '/url').respond(); |
+ http(method: 'GET', url: '/url', cache: false); |
+ flush(); |
+ })); |
+ }); |
}); |
- }); |
- // NOTE: We are punting on timeouts for now until we understand |
- // Dart futures fully. |
- xdescribe('timeout', () { |
+ // NOTE: We are punting on timeouts for now until we understand |
+ // Dart futures fully. |
+ xdescribe('timeout', () { |
- it('should abort requests when timeout promise resolves', inject(($q) { |
- var canceler = $q.defer(); |
+ it('should abort requests when timeout promise resolves', (q) { |
+ var canceler = q.defer(); |
- backend.expect('GET', '/some').respond(200); |
+ backend.expect('GET', '/some').respond(200); |
- http(method: 'GET', url: '/some', timeout: canceler.promise).error( |
- (data, status, headers, config) { |
- expect(data).toBeNull(); |
- expect(status).toEqual(0); |
- expect(headers()).toEqual({}); |
- expect(config.url).toEqual('/some'); |
- callback(); |
- }); |
+ http(method: 'GET', url: '/some', timeout: canceler.promise).error( |
+ (data, status, headers, config) { |
+ expect(data).toBeNull(); |
+ expect(status).toEqual(0); |
+ expect(headers()).toEqual({}); |
+ expect(config.url).toEqual('/some'); |
+ callback(); |
+ }); |
- //$rootScope.apply(() { |
+ //rootScope.apply(() { |
canceler.resolve(); |
- //}); |
+ //}); |
- expect(callback).toHaveBeenCalled(); |
- backend.verifyNoOutstandingExpectation(); |
- backend.verifyNoOutstandingRequest(); |
- })); |
- }); |
+ expect(callback).toHaveBeenCalled(); |
+ backend.verifyNoOutstandingExpectation(); |
+ backend.verifyNoOutstandingRequest(); |
+ }); |
+ }); |
- describe('pendingRequests', () { |
+ describe('pendingRequests', () { |
- it('should be an array of pending requests', async(() { |
- backend.when('GET').respond(200); |
- expect(http.pendingRequests.length).toEqual(0); |
+ it('should be an array of pending requests', async(() { |
+ backend.when('GET').respond(200); |
+ expect(http.pendingRequests.length).toEqual(0); |
- http(method: 'get', url: '/some'); |
- microLeap(); |
- expect(http.pendingRequests.length).toEqual(1); |
+ http(method: 'get', url: '/some'); |
+ microLeap(); |
+ expect(http.pendingRequests.length).toEqual(1); |
- flush(); |
- expect(http.pendingRequests.length).toEqual(0); |
- })); |
+ flush(); |
+ expect(http.pendingRequests.length).toEqual(0); |
+ })); |
- // TODO(deboer): I think this test is incorrect. |
- // pending requests should refer to the number of requests |
- // on-the-wire, not the number of times a URL was requested. |
- xit('should update pending requests even when served from cache', async(() { |
- var cache = new UnboundedCache(); |
- backend.when('GET').respond(200); |
+ // TODO(deboer): I think this test is incorrect. |
+ // pending requests should refer to the number of requests |
+ // on-the-wire, not the number of times a URL was requested. |
+ xit('should update pending requests even when served from cache', async(() { |
+ var cache = new UnboundedCache(); |
+ backend.when('GET').respond(200); |
- http(method: 'get', url: '/cached', cache: cache); |
- http(method: 'get', url: '/cached', cache: cache); |
- expect(http.pendingRequests.length).toEqual(2); |
+ http(method: 'get', url: '/cached', cache: cache); |
+ http(method: 'get', url: '/cached', cache: cache); |
+ expect(http.pendingRequests.length).toEqual(2); |
- flush(); |
+ flush(); |
- expect(http.pendingRequests.length).toEqual(0); |
+ expect(http.pendingRequests.length).toEqual(0); |
- http(method: 'get', url: '/cached', cache: true); |
- jasmine.spyOn(http.pendingRequests, 'add').andCallThrough(); |
- //expect(http.pendingRequests.add).toHaveBeenCalledOnce(); |
+ http(method: 'get', url: '/cached', cache: true); |
+ jasmine.spyOn(http.pendingRequests, 'add').andCallThrough(); |
+ //expect(http.pendingRequests.add).toHaveBeenCalledOnce(); |
- expect(http.pendingRequests.length).toEqual(0); |
- })); |
+ expect(http.pendingRequests.length).toEqual(0); |
+ })); |
- it('should remove the request before firing callbacks', async(() { |
- backend.when('GET').respond(200); |
- http(method: 'get', url: '/url').then((_) { |
- expect(http.pendingRequests.length).toEqual(0); |
- }); |
- microLeap(); |
+ it('should remove the request before firing callbacks', async(() { |
+ backend.when('GET').respond(200); |
+ http(method: 'get', url: '/url').then((_) { |
+ expect(http.pendingRequests.length).toEqual(0); |
+ }); |
+ microLeap(); |
- expect(http.pendingRequests.length).toEqual(1); |
- flush(); |
- })); |
- }); |
+ expect(http.pendingRequests.length).toEqual(1); |
+ flush(); |
+ })); |
+ }); |
- describe('defaults', () { |
+ describe('defaults', () { |
- it('should expose the defaults object at runtime', async(() { |
- expect(http.defaults).toBeDefined(); |
+ it('should expose the defaults object at runtime', async(() { |
+ expect(http.defaults).toBeDefined(); |
- http.defaults.headers['common']['foo'] = 'bar'; |
- backend.expect('GET', '/url', null, (headers) { |
- return headers['foo'] == 'bar'; |
- }).respond(''); |
+ http.defaults.headers['common']['foo'] = 'bar'; |
+ backend.expect('GET', '/url', null, (headers) { |
+ return headers['foo'] == 'bar'; |
+ }).respond(''); |
- http.get('/url'); |
- flush(); |
- })); |
+ http.get('/url'); |
+ flush(); |
+ })); |
+ }); |
}); |
- }); |
- describe('url rewriting', () { |
- beforeEach(module((Module module) { |
- module |
- ..type(UrlRewriter, implementedBy: SubstringRewriter); |
- })); |
+ describe('url rewriting', () { |
+ beforeEachModule((Module module) { |
+ module.type(UrlRewriter, implementedBy: SubstringRewriter); |
+ }); |
- it('should rewrite URLs before calling the backend', async(inject((Http http, NgZone zone) { |
- backend.when('GET', 'a').respond(200, VALUE); |
+ it('should rewrite URLs before calling the backend', async((Http http, VmTurnZone zone) { |
+ backend.when('GET', 'a').respond(200, VALUE); |
- var called = 0; |
- zone.run(() { |
- http.getString('a[not sent to backed]').then((v) { |
- expect(v).toEqual(VALUE); |
- called += 1; |
+ var called = 0; |
+ zone.run(() { |
+ http.get('a[not sent to backed]').then((v) { |
+ expect(v.responseText).toEqual(VALUE); |
+ called += 1; |
+ }); |
}); |
- }); |
- expect(called).toEqual(0); |
+ expect(called).toEqual(0); |
- flush(); |
+ flush(); |
- expect(called).toEqual(1); |
- }))); |
+ expect(called).toEqual(1); |
+ })); |
- it('should support pending requests for different raw URLs', async(inject((Http http, NgZone zone) { |
- backend.when('GET', 'a').respond(200, VALUE); |
+ it('should support pending requests for different raw URLs', async((Http http, VmTurnZone zone) { |
+ backend.when('GET', 'a').respond(200, VALUE); |
- var called = 0; |
- zone.run(() { |
- http.getString('a[some string]', cache: cache).then((v) { |
- expect(v).toEqual(VALUE); |
- called += 1; |
- }); |
- http.getString('a[different string]', cache: cache).then((v) { |
- expect(v).toEqual(VALUE); |
- called += 10; |
+ var called = 0; |
+ zone.run(() { |
+ http.get('a[some string]', cache: cache).then((v) { |
+ expect(v.responseText).toEqual(VALUE); |
+ called += 1; |
+ }); |
+ http.get('a[different string]', cache: cache).then((v) { |
+ expect(v.responseText).toEqual(VALUE); |
+ called += 10; |
+ }); |
}); |
- }); |
- expect(called).toEqual(0); |
- flush(); |
+ expect(called).toEqual(0); |
+ flush(); |
- expect(called).toEqual(11); |
- }))); |
+ expect(called).toEqual(11); |
+ })); |
- it('should support caching', async(inject((Http http, NgZone zone) { |
- var called = 0; |
- zone.run(() { |
- http.getString('fromCache', cache: cache).then((v) { |
- expect(v).toEqual(CACHED_VALUE); |
- called += 1; |
+ it('should support caching', async((Http http, VmTurnZone zone) { |
+ var called = 0; |
+ zone.run(() { |
+ http.get('fromCache', cache: cache).then((v) { |
+ expect(v.responseText).toEqual(CACHED_VALUE); |
+ called += 1; |
+ }); |
}); |
- }); |
- expect(called).toEqual(1); |
- }))); |
- }); |
+ expect(called).toEqual(1); |
+ })); |
+ }); |
- describe('caching', () { |
- it('should not cache if no cache is present', async(inject((Http http, NgZone zone) { |
- backend.when('GET', 'a').respond(200, VALUE, null); |
+ describe('caching', () { |
+ it('should not cache if no cache is present', async((Http http, VmTurnZone zone) { |
+ backend.when('GET', 'a').respond(200, VALUE, null); |
- var called = 0; |
- zone.run(() { |
- http.getString('a').then((v) { |
- expect(v).toEqual(VALUE); |
- called += 1; |
- }); |
- http.getString('a').then((v) { |
- expect(v).toEqual(VALUE); |
- called += 10; |
+ var called = 0; |
+ zone.run(() { |
+ http.get('a').then((v) { |
+ expect(v.responseText).toEqual(VALUE); |
+ called += 1; |
+ }); |
+ http.get('a').then((v) { |
+ expect(v.responseText).toEqual(VALUE); |
+ called += 10; |
+ }); |
}); |
- }); |
- expect(called).toEqual(0); |
+ expect(called).toEqual(0); |
- flush(); |
+ flush(); |
- expect(called).toEqual(11); |
- }))); |
+ expect(called).toEqual(11); |
+ })); |
- it('should return a pending request', async(inject((Http http, NgZone zone) { |
- backend.when('GET', 'a').respond(200, VALUE); |
+ it('should return a pending request', async((Http http, VmTurnZone zone) { |
+ backend.when('GET', 'a').respond(200, VALUE); |
- var called = 0; |
- zone.run(() { |
- http.getString('a', cache: cache).then((v) { |
- expect(v).toEqual(VALUE); |
- called += 1; |
- }); |
- http.getString('a', cache: cache).then((v) { |
- expect(v).toEqual(VALUE); |
- called += 10; |
+ var called = 0; |
+ zone.run(() { |
+ http.get('a', cache: cache).then((v) { |
+ expect(v.responseText).toEqual(VALUE); |
+ called += 1; |
+ }); |
+ http.get('a', cache: cache).then((v) { |
+ expect(v.responseText).toEqual(VALUE); |
+ called += 10; |
+ }); |
}); |
- }); |
- expect(called).toEqual(0); |
- flush(); |
+ expect(called).toEqual(0); |
+ flush(); |
- expect(called).toEqual(11); |
- }))); |
+ expect(called).toEqual(11); |
+ })); |
- it('should not return a pending request after the request is complete', async(inject((Http http, NgZone zone) { |
- backend.when('GET', 'a').respond(200, VALUE, null); |
+ it('should not return a pending request after the request is complete', async((Http http, VmTurnZone zone) { |
+ backend.when('GET', 'a').respond(200, VALUE, null); |
- var called = 0; |
- zone.run(() { |
- http.getString('a', cache: cache).then((v) { |
- expect(v).toEqual(VALUE); |
- called += 1; |
+ var called = 0; |
+ zone.run(() { |
+ http.get('a', cache: cache).then((v) { |
+ expect(v.responseText).toEqual(VALUE); |
+ called += 1; |
+ }); |
}); |
- }); |
- expect(called).toEqual(0); |
- flush(); |
+ expect(called).toEqual(0); |
+ flush(); |
- zone.run(() { |
- http.getString('a', cache: cache).then((v) { |
- expect(v).toEqual(VALUE); |
- called += 10; |
+ zone.run(() { |
+ http.get('a', cache: cache).then((v) { |
+ expect(v.responseText).toEqual(VALUE); |
+ called += 10; |
+ }); |
}); |
- }); |
- expect(called).toEqual(1); |
- flush(); |
+ expect(called).toEqual(1); |
+ flush(); |
- expect(called).toEqual(11); |
- }))); |
+ expect(called).toEqual(11); |
+ })); |
- it('should return a cached value if present', async(inject((Http http, NgZone zone) { |
- var called = 0; |
- // The URL string 'f' is primed in the FakeCache |
- zone.run(() { |
- http.getString('f', cache: cache).then((v) { |
- expect(v).toEqual(CACHED_VALUE); |
- called += 1; |
+ it('should return a cached value if present', async((Http http, VmTurnZone zone) { |
+ var called = 0; |
+ // The URL string 'f' is primed in the FakeCache |
+ zone.run(() { |
+ http.get('f', cache: cache).then((v) { |
+ expect(v.responseText).toEqual(CACHED_VALUE); |
+ called += 1; |
+ }); |
+ expect(called).toEqual(0); |
}); |
- expect(called).toEqual(0); |
- }); |
- expect(called).toEqual(1); |
- }))); |
- }); |
- |
- |
- describe('error handling', () { |
- it('should reject 404 status codes', async(inject((Http http, NgZone zone) { |
- backend.when('GET', '404.html').respond(404, VALUE); |
- |
- var response = null; |
- zone.run(() { |
- http.getString('404.html').then( |
- (v) => response = 'FAILED', |
- onError:(v) { assert(v != null); return response = v; }); |
- }); |
+ expect(called).toEqual(1); |
+ })); |
+ }); |
- expect(response).toEqual(null); |
- flush(); |
- expect(response.status).toEqual(404); |
- expect(response.toString()).toEqual('HTTP 404: val'); |
- }))); |
- }); |
+ describe('error handling', () { |
+ it('should reject 404 status codes', async((Http http, VmTurnZone zone) { |
+ backend.when('GET', '404.html').respond(404, VALUE); |
- describe('interceptors', () { |
- it('should chain request, requestReject, response and responseReject interceptors', async(() { |
- inject((HttpInterceptors interceptors) { |
- var savedConfig, savedResponse; |
- interceptors.add(new HttpInterceptor( |
- request: (config) { |
- config.url += '/1'; |
- savedConfig = config; |
- return new Future.error('/2'); |
- })); |
- interceptors.add(new HttpInterceptor( |
- requestError: (error) { |
- savedConfig.url += error; |
- return new Future.value(savedConfig); |
- })); |
- interceptors.add(new HttpInterceptor( |
- responseError: (rejection) => |
- new HttpResponse.copy(savedResponse, |
- data: savedResponse.data + rejection) |
- )); |
- interceptors.add(new HttpInterceptor( |
- response: (response) { |
- savedResponse = new HttpResponse.copy( |
- response, data: response.data + ':1'); |
- return new Future.error(':2'); |
- })); |
- }); |
- inject((Http http) { |
- var response; |
- backend.expect('GET', '/url/1/2').respond('response'); |
- http(method: 'GET', url: '/url').then((r) { |
- response = r; |
+ var response = null; |
+ zone.run(() { |
+ http.get('404.html').then( |
+ (v) => response = 'FAILED', |
+ onError:(v) { assert(v != null); return response = v; }); |
}); |
- flush(); |
- expect(response.data).toEqual('response:1:2'); |
- }); |
- })); |
- |
- |
- it('should verify order of execution', async( |
- inject((HttpInterceptors interceptors, Http http) { |
- interceptors.add(new HttpInterceptor( |
- request: (config) { |
- config.url += '/outer'; |
- return config; |
- }, |
- response: (response) { |
- return new HttpResponse.copy( |
- response, data: '{' + response.data + '} outer'); |
- })); |
- interceptors.add(new HttpInterceptor( |
- request: (config) { |
- config.url += '/inner'; |
- return config; |
- }, |
- response: (response) { |
- return new HttpResponse.copy( |
- response, data: '{' + response.data + '} inner'); |
- })); |
- var response; |
- backend.expect('GET', '/url/outer/inner').respond('response'); |
- http(method: 'GET', url: '/url').then((r) { |
- response = r; |
- }); |
- flush(); |
- expect(response.data).toEqual('{{response} inner} outer'); |
- }))); |
- |
- describe('transformData', () { |
- Http http; |
- var callback; |
- |
- beforeEach(inject((Http h) { |
- http = h; |
- callback = jasmine.createSpy('callback'); |
+ expect(response).toEqual(null); |
+ flush(); |
+ expect(response.status).toEqual(404); |
+ expect(response.toString()).toEqual('HTTP 404: val'); |
})); |
+ }); |
- describe('request', () { |
- |
- describe('default', () { |
- it('should transform object into json', async(() { |
- backend.expect('POST', '/url', '{"one":"two"}').respond(''); |
- http(method: 'POST', url: '/url', data: {'one': 'two'}); |
- })); |
+ describe('interceptors', () { |
+ it('should chain request, requestReject, response and responseReject interceptors', async(() { |
+ (HttpInterceptors interceptors, Http http) { |
+ var savedConfig, savedResponse; |
+ interceptors.add(new HttpInterceptor( |
+ request: (config) { |
+ config.url += '/1'; |
+ savedConfig = config; |
+ return new Future.error('/2'); |
+ })); |
+ interceptors.add(new HttpInterceptor( |
+ requestError: (error) { |
+ savedConfig.url += error; |
+ return new Future.value(savedConfig); |
+ })); |
+ interceptors.add(new HttpInterceptor( |
+ responseError: (rejection) => |
+ new HttpResponse.copy(savedResponse, |
+ data: savedResponse.data + rejection) |
+ )); |
+ interceptors.add(new HttpInterceptor( |
+ response: (response) { |
+ savedResponse = new HttpResponse.copy( |
+ response, data: response.data + ':1'); |
+ return new Future.error(':2'); |
+ })); |
+ var response; |
+ backend.expect('GET', '/url/1/2').respond('response'); |
+ http(method: 'GET', url: '/url').then((r) { |
+ response = r; |
+ }); |
+ flush(); |
+ expect(response.data).toEqual('response:1:2'); |
+ }; |
+ })); |
- it('should ignore strings', async(() { |
- backend.expect('POST', '/url', 'string-data').respond(''); |
- http(method: 'POST', url: '/url', data: 'string-data'); |
+ it('should verify order of execution', async( |
+ (HttpInterceptors interceptors, Http http) { |
+ interceptors.add(new HttpInterceptor( |
+ request: (config) { |
+ config.url += '/outer'; |
+ return config; |
+ }, |
+ response: (response) { |
+ return new HttpResponse.copy( |
+ response, data: '{' + response.data + '} outer'); |
+ })); |
+ interceptors.add(new HttpInterceptor( |
+ request: (config) { |
+ config.url += '/inner'; |
+ return config; |
+ }, |
+ response: (response) { |
+ return new HttpResponse.copy( |
+ response, data: '{' + response.data + '} inner'); |
+ })); |
+ |
+ var response; |
+ backend.expect('GET', '/url/outer/inner').respond('response'); |
+ http(method: 'GET', url: '/url').then((r) { |
+ response = r; |
+ }); |
+ flush(); |
+ expect(response.data).toEqual('{{response} inner} outer'); |
})); |
+ describe('transformData', () { |
+ Http http; |
+ var callback; |
- it('should ignore File objects', async(() { |
- var file = new FakeFile(); |
- expect(file is File).toBeTruthy(); |
- |
- backend.expect('POST', '/some', file).respond(''); |
- http(method: 'POST', url: '/some', data: file); |
- })); |
+ beforeEach((Http h) { |
+ http = h; |
+ callback = jasmine.createSpy('callback'); |
}); |
+ describe('request', () { |
- it('should have access to request headers', async(() { |
- backend.expect('POST', '/url', 'header1').respond(200); |
- http.post('/url', 'req', |
- headers: {'h1': 'header1'}, |
- interceptors: new HttpInterceptor(request: (config) { |
- config.data = config.header('h1'); |
- return config; |
- }) |
- ).then(callback); |
- flush(); |
+ describe('default', () { |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
+ it('should transform object into json', async(() { |
+ backend.expect('POST', '/url', '{"one":"two"}').respond(''); |
+ http(method: 'POST', url: '/url', data: {'one': 'two'}); |
+ flush(); |
+ })); |
- it('should pipeline more functions', async(() { |
- backend.expect('POST', '/url', 'REQ-FIRST:V1').respond(200); |
- http.post('/url', 'req', |
- headers: {'h1': 'v1'}, |
- interceptors: new HttpInterceptors.of([ |
- new HttpInterceptor(request: (config) { |
- config.data = config.data + '-first' + ':' + config.header('h1'); |
- return config; |
- }), |
- new HttpInterceptor(request: (config) { |
- config.data = config.data.toUpperCase(); |
- return config; |
- }) |
- ]) |
- ).then(callback); |
- flush(); |
+ it('should ignore strings', async(() { |
+ backend.expect('POST', '/url', 'string-data').respond(''); |
+ http(method: 'POST', url: '/url', data: 'string-data'); |
+ flush(); |
+ })); |
- expect(callback).toHaveBeenCalledOnce(); |
- })); |
- }); |
+ it('should ignore File objects', async(() { |
+ var file = new FakeFile(); |
+ expect(file is File).toBeTruthy(); |
- describe('response', () { |
+ backend.expect('POST', '/some', file).respond(''); |
+ http(method: 'POST', url: '/some', data: file); |
+ flush(); |
+ })); |
+ }); |
- describe('default', () { |
- it('should deserialize json objects', async(() { |
- backend.expect('GET', '/url').respond('{"foo":"bar","baz":23}'); |
- http(method: 'GET', url: '/url').then(callback); |
+ it('should have access to request headers', async(() { |
+ backend.expect('POST', '/url', 'header1').respond(200); |
+ http.post('/url', 'req', |
+ headers: {'h1': 'header1'}, |
+ interceptors: new HttpInterceptor(request: (config) { |
+ config.data = config.header('h1'); |
+ return config; |
+ }) |
+ ).then(callback); |
flush(); |
expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual({'foo': 'bar', 'baz': 23}); |
})); |
- it('should deserialize json arrays', async(() { |
- backend.expect('GET', '/url').respond('[1, "abc", {"foo":"bar"}]'); |
- http(method: 'GET', url: '/url').then(callback); |
+ it('should pipeline more functions', async(() { |
+ backend.expect('POST', '/url', 'REQ-FIRST:V1').respond(200); |
+ http.post('/url', 'req', |
+ headers: {'h1': 'v1'}, |
+ interceptors: new HttpInterceptors.of([ |
+ new HttpInterceptor(request: (config) { |
+ config.data = config.data + '-first' + ':' + config.header('h1'); |
+ return config; |
+ }), |
+ new HttpInterceptor(request: (config) { |
+ config.data = config.data.toUpperCase(); |
+ return config; |
+ }) |
+ ]) |
+ ).then(callback); |
flush(); |
expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual([1, 'abc', {'foo': 'bar'}]); |
})); |
+ }); |
- it('should deserialize json with security prefix', async(() { |
- backend.expect('GET', '/url').respond(')]}\',\n[1, "abc", {"foo":"bar"}]'); |
- http(method: 'GET', url: '/url').then(callback); |
- flush(); |
+ describe('response', () { |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual([1, 'abc', {'foo':'bar'}]); |
- })); |
+ describe('default', () { |
+ it('should deserialize json objects', async(() { |
+ backend.expect('GET', '/url').respond('{"foo":"bar","baz":23}'); |
+ http(method: 'GET', url: '/url').then(callback); |
+ flush(); |
- it('should deserialize json with security prefix ")]}\'"', async(() { |
- backend.expect('GET', '/url').respond(')]}\'\n\n[1, "abc", {"foo":"bar"}]'); |
- http(method: 'GET', url: '/url').then(callback); |
- flush(); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual({'foo': 'bar', 'baz': 23}); |
+ })); |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual([1, 'abc', {'foo':'bar'}]); |
- })); |
+ it('should deserialize json arrays', async(() { |
+ backend.expect('GET', '/url').respond('[1, "abc", {"foo":"bar"}]'); |
+ http(method: 'GET', url: '/url').then(callback); |
+ flush(); |
- it('should call onError on a JSON parse error', async(() { |
- backend.expect('GET', '/url').respond('[x]'); |
- var callbackCalled = false; |
- var onErrorCalled = false; |
- http.get('/url').then((_) { |
- callbackCalled = true; |
- }, onError: (e,s) { |
- // Dartium throws "Unexpected character" |
- // dart2js throws "Unexpected token" |
- expect('$e').toContain('Unexpected'); |
- onErrorCalled = true; |
- }); |
- flush(); |
- expect(callbackCalled).toBeFalsy(); |
- expect(onErrorCalled).toBeTruthy(); |
- })); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual([1, 'abc', {'foo': 'bar'}]); |
+ })); |
- it('should not deserialize tpl beginning with ng expression', async(() { |
- backend.expect('GET', '/url').respond('{{some}}'); |
- http.get('/url').then(callback); |
- flush(); |
+ it('should deserialize json with security prefix', async(() { |
+ backend.expect('GET', '/url').respond(')]}\',\n[1, "abc", {"foo":"bar"}]'); |
+ http(method: 'GET', url: '/url').then(callback); |
+ flush(); |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual('{{some}}'); |
- })); |
- }); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual([1, 'abc', {'foo':'bar'}]); |
+ })); |
- it('should have access to response headers', async(() { |
- backend.expect('GET', '/url').respond(200, 'response', {'h1': 'header1'}); |
- http.get('/url', |
- interceptors: new HttpInterceptor(response: (r) { |
- return new HttpResponse.copy(r, data: r.headers('h1')); |
- }) |
- ).then(callback); |
- flush(); |
+ it('should deserialize json with security prefix ")]}\'"', async(() { |
+ backend.expect('GET', '/url').respond(')]}\'\n\n[1, "abc", {"foo":"bar"}]'); |
+ http(method: 'GET', url: '/url').then(callback); |
+ flush(); |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual('header1'); |
- })); |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual([1, 'abc', {'foo':'bar'}]); |
+ })); |
- it('should pipeline more functions', async(() { |
- backend.expect('POST', '/url').respond(200, 'resp', {'h1': 'v1'}); |
- http.post('/url', '', interceptors: new HttpInterceptors.of([ |
- new HttpInterceptor(response: (r) { |
- return new HttpResponse.copy(r, data: r.data.toUpperCase()); |
- }), |
- new HttpInterceptor(response: (r) { |
- return new HttpResponse.copy(r, data: r.data + '-first' + ':' + r.headers('h1')); |
- })])).then(callback); |
- flush(); |
- expect(callback).toHaveBeenCalledOnce(); |
- expect(callback.mostRecentCall.args[0].data).toEqual('RESP-FIRST:V1'); |
- })); |
+ it('should call onError on a JSON parse error', async(() { |
+ backend.expect('GET', '/url').respond('[x]'); |
+ var callbackCalled = false; |
+ var onErrorCalled = false; |
+ http.get('/url').then((_) { |
+ callbackCalled = true; |
+ }, onError: (e,s) { |
+ // Dartium throws "Unexpected character" |
+ // dart2js/Chrome throws "Unexpected token" |
+ // dart2js/Firefox throw "unexpected character" |
+ expect('$e').toContain('nexpected'); |
+ onErrorCalled = true; |
+ }); |
+ flush(); |
+ expect(callbackCalled).toBeFalsy(); |
+ expect(onErrorCalled).toBeTruthy(); |
+ })); |
+ |
+ |
+ it('should not deserialize tpl beginning with ng expression', async(() { |
+ backend.expect('GET', '/url').respond('{{some}}'); |
+ http.get('/url').then(callback); |
+ flush(); |
+ |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual('{{some}}'); |
+ })); |
+ }); |
+ |
+ |
+ it('should have access to response headers', async(() { |
+ backend.expect('GET', '/url').respond(200, 'response', {'h1': 'header1'}); |
+ http.get('/url', |
+ interceptors: new HttpInterceptor(response: (r) { |
+ return new HttpResponse.copy(r, data: r.headers('h1')); |
+ }) |
+ ).then(callback); |
+ flush(); |
+ |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual('header1'); |
+ })); |
+ |
+ it('should pipeline more functions', async(() { |
+ backend.expect('POST', '/url').respond(200, 'resp', {'h1': 'v1'}); |
+ http.post('/url', '', interceptors: new HttpInterceptors.of([ |
+ new HttpInterceptor(response: (r) { |
+ return new HttpResponse.copy(r, data: r.data.toUpperCase()); |
+ }), |
+ new HttpInterceptor(response: (r) { |
+ return new HttpResponse.copy(r, data: r.data + '-first' + ':' + r.headers('h1')); |
+ })])).then(callback); |
+ flush(); |
+ |
+ expect(callback).toHaveBeenCalledOnce(); |
+ expect(callback.mostRecentCall.args[0].data).toEqual('RESP-FIRST:V1'); |
+ })); |
+ }); |
}); |
}); |
}); |
-}); |
+} |
class FakeFile implements File { |
DateTime get lastModifiedDate => null; |