@@ -87,27 +87,81 @@ describe('browser', function(){
87
87
88
88
describe ( 'xhr' , function ( ) {
89
89
describe ( 'JSON' , function ( ) {
90
- it ( 'should add script tag for request' , function ( ) {
91
- var callback = jasmine . createSpy ( 'callback' ) ;
92
- var log = "" ;
93
- browser . xhr ( 'JSON' , 'http://example.org/path?cb=JSON_CALLBACK' , null , function ( code , data ) {
94
- log += code + ':' + data + ';' ;
95
- } ) ;
96
- browser . notifyWhenNoOutstandingRequests ( callback ) ;
97
- expect ( callback ) . not . toHaveBeenCalled ( ) ;
98
- expect ( scripts . length ) . toEqual ( 1 ) ;
99
- var script = scripts [ 0 ] ;
100
- var url = script . src . split ( '?cb=' ) ;
101
- expect ( url [ 0 ] ) . toEqual ( 'http://example.org/path' ) ;
102
- expect ( typeof fakeWindow [ url [ 1 ] ] ) . toEqual ( $function ) ;
103
- fakeWindow [ url [ 1 ] ] ( 'data' ) ;
104
- expect ( callback ) . toHaveBeenCalled ( ) ;
105
- expect ( log ) . toEqual ( '200:data;' ) ;
106
- expect ( scripts ) . toEqual ( removedScripts ) ;
107
- expect ( fakeWindow [ url [ 1 ] ] ) . toBeUndefined ( ) ;
90
+ var log ;
91
+
92
+ function callback ( code , data ) {
93
+ log += code + ':' + data + ';' ;
94
+ }
95
+
96
+ beforeEach ( function ( ) {
97
+ log = "" ;
108
98
} ) ;
99
+
100
+
101
+ // We don't have unit tests for IE because script.readyState is readOnly.
102
+ // Instead we run e2e tests on all browsers - see e2e for $xhr.
103
+ if ( ! msie ) {
104
+
105
+ it ( 'should add script tag for JSONP request' , function ( ) {
106
+ var notify = jasmine . createSpy ( 'notify' ) ;
107
+ browser . xhr ( 'JSON' , 'http://example.org/path?cb=JSON_CALLBACK' , null , callback ) ;
108
+ browser . notifyWhenNoOutstandingRequests ( notify ) ;
109
+ expect ( notify ) . not . toHaveBeenCalled ( ) ;
110
+ expect ( scripts . length ) . toEqual ( 1 ) ;
111
+ var script = scripts [ 0 ] ;
112
+ var url = script . src . split ( '?cb=' ) ;
113
+ expect ( url [ 0 ] ) . toEqual ( 'http://example.org/path' ) ;
114
+ expect ( typeof fakeWindow [ url [ 1 ] ] ) . toEqual ( $function ) ;
115
+ fakeWindow [ url [ 1 ] ] ( 'data' ) ;
116
+ script . onload ( ) ;
117
+
118
+ expect ( notify ) . toHaveBeenCalled ( ) ;
119
+ expect ( log ) . toEqual ( '200:data;' ) ;
120
+ expect ( scripts ) . toEqual ( removedScripts ) ;
121
+ expect ( fakeWindow [ url [ 1 ] ] ) . toBeUndefined ( ) ;
122
+ } ) ;
123
+
124
+
125
+ it ( 'should call callback when script fails to load' , function ( ) {
126
+ browser . xhr ( 'JSON' , 'http://example.org/path?cb=JSON_CALLBACK' , null , callback ) ;
127
+ var script = scripts [ 0 ] ;
128
+ expect ( typeof script . onload ) . toBe ( $function ) ;
129
+ expect ( typeof script . onerror ) . toBe ( $function ) ;
130
+ script . onerror ( ) ;
131
+
132
+ expect ( log ) . toEqual ( 'undefined:undefined;' ) ;
133
+ } ) ;
134
+
135
+
136
+ it ( 'should update the outstandingRequests counter for successful requests' , function ( ) {
137
+ var notify = jasmine . createSpy ( 'notify' ) ;
138
+ browser . xhr ( 'JSON' , 'http://example.org/path?cb=JSON_CALLBACK' , null , callback ) ;
139
+ browser . notifyWhenNoOutstandingRequests ( notify ) ;
140
+ expect ( notify ) . not . toHaveBeenCalled ( ) ;
141
+
142
+ var script = scripts [ 0 ] ;
143
+ var url = script . src . split ( '?cb=' ) ;
144
+ fakeWindow [ url [ 1 ] ] ( 'data' ) ;
145
+ script . onload ( ) ;
146
+
147
+ expect ( notify ) . toHaveBeenCalled ( ) ;
148
+ } ) ;
149
+
150
+
151
+ it ( 'should update the outstandingRequests counter for failed requests' , function ( ) {
152
+ var notify = jasmine . createSpy ( 'notify' ) ;
153
+ browser . xhr ( 'JSON' , 'http://example.org/path?cb=JSON_CALLBACK' , null , callback ) ;
154
+ browser . notifyWhenNoOutstandingRequests ( notify ) ;
155
+ expect ( notify ) . not . toHaveBeenCalled ( ) ;
156
+
157
+ scripts [ 0 ] . onerror ( ) ;
158
+
159
+ expect ( notify ) . toHaveBeenCalled ( ) ;
160
+ } ) ;
161
+ }
109
162
} ) ;
110
163
164
+
111
165
it ( 'should normalize IE\'s 1223 status code into 204' , function ( ) {
112
166
var callback = jasmine . createSpy ( 'XHR' ) ;
113
167
0 commit comments