Skip to content

Commit 253b51a

Browse files
committed
Work around a typings issue in @angular/http test
1 parent 5985bb5 commit 253b51a

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

tests/app/tests/http.ts

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//make sure you import mocha-config before @angular/core
22
import {assert} from "./test-config";
33
import {
4-
async,
5-
inject,
6-
beforeEach,
7-
beforeEachProviders
4+
async,
5+
inject,
6+
beforeEach,
7+
beforeEachProviders
88
} from '@angular/core/testing';
99
import {provide, ReflectiveInjector} from '@angular/core';
1010
import {BaseRequestOptions, ConnectionBackend, Http, HTTP_PROVIDERS, Response, ResponseOptions} from '@angular/http';
@@ -15,48 +15,49 @@ import {NSFileSystem} from "nativescript-angular/file-system/ns-file-system";
1515
import {NSFileSystemMock, FileResponses} from './mocks/ns-file-system.mock';
1616

1717
describe("Http", () => {
18-
let http: Http;
19-
let backend: MockBackend;
18+
let http: Http;
19+
let backend: MockBackend;
2020

21-
beforeEach(() => {
22-
let injector = ReflectiveInjector.resolveAndCreate([
23-
HTTP_PROVIDERS,
24-
BaseRequestOptions,
25-
MockBackend,
26-
provide(NSFileSystem, { useClass: NSFileSystemMock }),
27-
provide(Http, {
28-
useFactory: function (backend: ConnectionBackend, defaultOptions: BaseRequestOptions, nsFileSystem: NSFileSystem) {
29-
return new NSHttp(backend, defaultOptions, nsFileSystem);
30-
},
31-
deps: [MockBackend, BaseRequestOptions, NSFileSystem]
32-
})
33-
]);
34-
35-
backend = injector.get(MockBackend);
36-
http = injector.get(Http);
37-
});
21+
beforeEach(() => {
22+
let injector = ReflectiveInjector.resolveAndCreate([
23+
HTTP_PROVIDERS,
24+
BaseRequestOptions,
25+
MockBackend,
26+
provide(NSFileSystem, { useClass: NSFileSystemMock }),
27+
provide(Http, {
28+
useFactory: function (backend: ConnectionBackend, defaultOptions: BaseRequestOptions, nsFileSystem: NSFileSystem) {
29+
//HACK: cast backend to any to work around an angular typings problem
30+
return new NSHttp(<any>backend, defaultOptions, nsFileSystem);
31+
},
32+
deps: [MockBackend, BaseRequestOptions, NSFileSystem]
33+
})
34+
]);
3835

39-
it("should work with local files prefixed with '~'", () => {
40-
http.get('~/test.json').map(res => res.json()).subscribe((response: any) => {
41-
assert.strictEqual(3, response.length);
42-
assert.strictEqual('Alex', response[0].name);
36+
backend = injector.get(MockBackend);
37+
http = injector.get(Http);
4338
});
44-
});
4539

46-
it("should work with local files prefixed with '/'", () => {
47-
http.get('/test.json').map(res => res.json()).subscribe((response: any) => {
48-
assert.strictEqual(3, response.length);
49-
assert.strictEqual('Panayot', response[2].name);
40+
it("should work with local files prefixed with '~'", () => {
41+
http.get('~/test.json').map(res => res.json()).subscribe((response: any) => {
42+
assert.strictEqual(3, response.length);
43+
assert.strictEqual('Alex', response[0].name);
44+
});
5045
});
51-
});
5246

53-
it("should work with remote files", () => {
54-
let connection: any;
55-
backend.connections.subscribe((c: any) => connection = c);
56-
http.get('http://www.nativescript.org/test.json').map(res => res.json()).subscribe((response: any) => {
57-
assert.strictEqual(3, response.length);
58-
assert.strictEqual('Rosen', response[1].name);
47+
it("should work with local files prefixed with '/'", () => {
48+
http.get('/test.json').map(res => res.json()).subscribe((response: any) => {
49+
assert.strictEqual(3, response.length);
50+
assert.strictEqual('Panayot', response[2].name);
51+
});
52+
});
53+
54+
it("should work with remote files", () => {
55+
let connection: any;
56+
backend.connections.subscribe((c: any) => connection = c);
57+
http.get('http://www.nativescript.org/test.json').map(res => res.json()).subscribe((response: any) => {
58+
assert.strictEqual(3, response.length);
59+
assert.strictEqual('Rosen', response[1].name);
60+
});
61+
connection.mockRespond(new Response(new ResponseOptions({ body: FileResponses.AWESOME_TEAM })));
5962
});
60-
connection.mockRespond(new Response(new ResponseOptions({ body: FileResponses.AWESOME_TEAM })));
61-
});
6263
});

0 commit comments

Comments
 (0)