| 
									
										
										
										
											2015-05-27 13:48:24 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   xit | 
					
						
							| 
									
										
										
										
											2015-10-13 00:29:13 -07:00
										 |  |  | } from 'angular2/testing_internal'; | 
					
						
							| 
									
										
										
										
											2015-05-27 13:48:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-13 11:21:16 -08:00
										 |  |  | import {XHRImpl} from 'angular2/src/platform/browser/xhr_impl'; | 
					
						
							| 
									
										
										
										
											2015-11-06 17:34:07 -08:00
										 |  |  | import {PromiseWrapper} from 'angular2/src/facade/async'; | 
					
						
							| 
									
										
										
										
											2015-05-27 13:48:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('XHRImpl', () => { | 
					
						
							| 
									
										
										
										
											2015-06-11 18:50:41 -07:00
										 |  |  |     var xhr: XHRImpl; | 
					
						
							| 
									
										
										
										
											2015-08-20 14:28:25 -07:00
										 |  |  |     var url200 = '/base/modules/angular2/test/core/services/static_assets/200.html'; | 
					
						
							|  |  |  |     var url404 = '/base/modules/angular2/test/core/services/static_assets/404.html'; | 
					
						
							| 
									
										
										
										
											2015-05-27 13:48:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     beforeEach(() => { xhr = new XHRImpl(); }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should resolve the Promise with the file content on success', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |          xhr.get(url200).then((text) => { | 
					
						
							|  |  |  |            expect(text.trim()).toEqual('<p>hey</p>'); | 
					
						
							|  |  |  |            async.done(); | 
					
						
							|  |  |  |          }); | 
					
						
							| 
									
										
										
										
											2015-06-02 16:29:09 +02:00
										 |  |  |        }), 10000); | 
					
						
							| 
									
										
										
										
											2015-05-27 13:48:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should reject the Promise on failure', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |          PromiseWrapper.catchError(xhr.get(url404), (e) => { | 
					
						
							|  |  |  |            expect(e).toEqual(`Failed to load ${url404}`); | 
					
						
							|  |  |  |            async.done(); | 
					
						
							| 
									
										
										
										
											2015-06-11 18:50:41 -07:00
										 |  |  |            return null; | 
					
						
							| 
									
										
										
										
											2015-05-27 13:48:24 -07:00
										 |  |  |          }); | 
					
						
							| 
									
										
										
										
											2015-06-02 16:29:09 +02:00
										 |  |  |        }), 10000); | 
					
						
							| 
									
										
										
										
											2015-05-27 13:48:24 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |