X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions modules/http/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {JSONPBackend, JSONPConnection} from 'http/src/backends/jsonp_backend';
import {BrowserXhr} from 'http/src/backends/browser_xhr';
import {BrowserJsonp} from 'http/src/backends/browser_jsonp';
import {BaseRequestOptions, RequestOptions} from 'http/src/base_request_options';
import {ConnectionBackend} from 'http/src/interfaces';
import {BaseResponseOptions, ResponseOptions} from 'http/src/base_response_options';

export {MockConnection, MockBackend} from 'http/src/backends/mock_backend';
Expand Down Expand Up @@ -62,19 +61,26 @@ export {URLSearchParams} from 'http/src/url_search_params';
*
*/
export const HTTP_BINDINGS: List<any> = [
bind(ConnectionBackend)
.toClass(XHRBackend),
// TODO(pascal): use factory type annotations once supported in DI
// issue: https://github.com/angular/angular/issues/3183
bind(Http)
.toFactory((xhrBackend, requestOptions) => { return new Http(xhrBackend, requestOptions);},
[XHRBackend, RequestOptions]),
BrowserXhr,
bind(RequestOptions).toClass(BaseRequestOptions),
bind(ResponseOptions).toClass(BaseResponseOptions),
Http
XHRBackend
];

export const JSONP_BINDINGS: List<any> = [
bind(ConnectionBackend)
.toClass(JSONPBackend),
// TODO(pascal): use factory type annotations once supported in DI
// issue: https://github.com/angular/angular/issues/3183
bind(Jsonp)
.toFactory(
(jsonpBackend, requestOptions) => { return new Jsonp(jsonpBackend, requestOptions);},
[JSONPBackend, RequestOptions]),
BrowserJsonp,
bind(RequestOptions).toClass(BaseRequestOptions),
bind(ResponseOptions).toClass(BaseResponseOptions),
Jsonp
JSONPBackend
];
62 changes: 60 additions & 2 deletions modules/http/test/http_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
import {
BaseRequestOptions,
ConnectionBackend,
Http,
Request,
RequestMethods,
RequestOptions,
Response,
ResponseOptions,
URLSearchParams
URLSearchParams,
JSONP_BINDINGS,
HTTP_BINDINGS,
XHRBackend,
JSONPBackend,
Http,
Jsonp
} from 'http/http';

class SpyObserver extends SpyObject {
Expand All @@ -39,6 +44,59 @@ class SpyObserver extends SpyObject {
}

export function main() {
describe('injectables', () => {
var url = 'http://foo.bar';
var http: Http;
var parentInjector: Injector;
var childInjector: Injector;
var jsonpBackend: MockBackend;
var xhrBackend: MockBackend;
var jsonp: Jsonp;
var http: Http;

it('should allow using jsonpInjectables and httpInjectables in same injector',
inject([AsyncTestCompleter], (async) => {
parentInjector = Injector.resolveAndCreate(
[bind(XHRBackend).toClass(MockBackend), bind(JSONPBackend).toClass(MockBackend)]);

childInjector = parentInjector.resolveAndCreateChild([
HTTP_BINDINGS,
JSONP_BINDINGS,
bind(XHRBackend).toClass(MockBackend),
bind(JSONPBackend).toClass(MockBackend)
]);

http = childInjector.get(Http);
jsonp = childInjector.get(Jsonp);
jsonpBackend = childInjector.get(JSONPBackend);
xhrBackend = childInjector.get(XHRBackend);

var xhrCreatedConnections = 0;
var jsonpCreatedConnections = 0;


ObservableWrapper.subscribe(xhrBackend.connections, () => {
xhrCreatedConnections++;
expect(xhrCreatedConnections).toEqual(1);
if (jsonpCreatedConnections) {
async.done();
}
});

ObservableWrapper.subscribe(http.get(url), () => {});

ObservableWrapper.subscribe(jsonpBackend.connections, () => {
jsonpCreatedConnections++;
expect(jsonpCreatedConnections).toEqual(1);
if (xhrCreatedConnections) {
async.done();
}
});

ObservableWrapper.subscribe(jsonp.request(url), () => {});
}));
});

describe('http', () => {
var url = 'http://foo.bar';
var http: Http;
Expand Down
X Tutup