@@ -4,44 +4,54 @@ describe('$templateRequest', function() {
4
4
5
5
describe ( 'provider' , function ( ) {
6
6
7
- describe ( 'acceptHeaders ' , function ( ) {
7
+ describe ( 'httpOptions ' , function ( ) {
8
8
9
- it ( 'should default to undefined and fallback to $http accept headers ' , function ( ) {
9
+ it ( 'should default to undefined and fallback to default $http options ' , function ( ) {
10
10
11
11
var defaultHeader ;
12
12
13
- module ( function ( $templateRequestProvider , $httpProvider ) {
14
- defaultHeader = $httpProvider . defaults . headers . get || $httpProvider . defaults . headers . common ;
15
- expect ( $templateRequestProvider . acceptHeaders ( ) ) . toBeUndefined ( ) ;
13
+ module ( function ( $templateRequestProvider ) {
14
+ expect ( $templateRequestProvider . httpOptions ( ) ) . toBeUndefined ( ) ;
16
15
} ) ;
17
16
18
- inject ( function ( $templateRequest , $httpBackend ) {
19
- $httpBackend . expectGET ( 'tpl.html' , defaultHeader ) . respond ( ) ;
17
+ inject ( function ( $templateRequest , $http , $templateCache ) {
18
+ spyOn ( $http , 'get' ) . andCallThrough ( ) ;
19
+
20
20
$templateRequest ( 'tpl.html' ) ;
21
- $httpBackend . verifyNoOutstandingExpectation ( ) ;
21
+
22
+ expect ( $http . get ) . toHaveBeenCalledOnceWith ( 'tpl.html' , {
23
+ cache : $templateCache ,
24
+ transformResponse : [ ]
25
+ } ) ;
22
26
} ) ;
23
27
24
28
} ) ;
25
29
26
30
it ( 'should be configurable' , function ( ) {
27
31
32
+ function someTransform ( ) { }
33
+
28
34
var expectedHeader ;
29
35
30
36
module ( function ( $templateRequestProvider , $httpProvider ) {
31
37
32
- // Configure the standard $http headers to something unusual
33
- $httpProvider . defaults . headers . get = { 'Other' : 'header value' } ;
34
- // Configure the template request service to provide a specific accept header
35
- $templateRequestProvider . acceptHeaders ( 'moo' ) ;
36
-
37
- // Compute what we expect the actual header object to be
38
- expectedHeader = extend ( $httpProvider . defaults . headers . get , { Accept : 'moo' } ) ;
38
+ // Configure the template request service to provide specific headers and transforms
39
+ $templateRequestProvider . httpOptions ( {
40
+ headers : { Accept : 'moo' } ,
41
+ transformResponse : [ someTransform ]
42
+ } ) ;
39
43
} ) ;
40
44
41
- inject ( function ( $templateRequest , $httpBackend ) {
42
- $httpBackend . expectGET ( 'tpl.html' , expectedHeader ) . respond ( ) ;
45
+ inject ( function ( $templateRequest , $http , $templateCache ) {
46
+ spyOn ( $http , 'get' ) . andCallThrough ( ) ;
47
+
43
48
$templateRequest ( 'tpl.html' ) ;
44
- $httpBackend . verifyNoOutstandingExpectation ( ) ;
49
+
50
+ expect ( $http . get ) . toHaveBeenCalledOnceWith ( 'tpl.html' , {
51
+ cache : $templateCache ,
52
+ transformResponse : [ someTransform ] ,
53
+ headers : { Accept : 'moo' }
54
+ } ) ;
45
55
} ) ;
46
56
} ) ;
47
57
} ) ;
0 commit comments