1
1
//make sure you import mocha-config before @angular/core
2
2
import { assert } from "./test-config" ;
3
3
import {
4
- async ,
5
- inject ,
6
- beforeEach ,
7
- beforeEachProviders
4
+ async ,
5
+ inject ,
6
+ beforeEach ,
7
+ beforeEachProviders
8
8
} from '@angular/core/testing' ;
9
9
import { provide , ReflectiveInjector } from '@angular/core' ;
10
10
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";
15
15
import { NSFileSystemMock , FileResponses } from './mocks/ns-file-system.mock' ;
16
16
17
17
describe ( "Http" , ( ) => {
18
- let http : Http ;
19
- let backend : MockBackend ;
18
+ let http : Http ;
19
+ let backend : MockBackend ;
20
20
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
+ ] ) ;
38
35
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 ) ;
43
38
} ) ;
44
- } ) ;
45
39
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
+ } ) ;
50
45
} ) ;
51
- } ) ;
52
46
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 } ) ) ) ;
59
62
} ) ;
60
- connection . mockRespond ( new Response ( new ResponseOptions ( { body : FileResponses . AWESOME_TEAM } ) ) ) ;
61
- } ) ;
62
63
} ) ;
0 commit comments