| 
									
										
										
										
											2016-04-12 09:40:37 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   it, | 
					
						
							| 
									
										
										
										
											2016-05-19 14:31:21 -07:00
										 |  |  |   xit, | 
					
						
							|  |  |  |   AsyncTestCompleter | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | } from '@angular/core/testing/testing_internal'; | 
					
						
							|  |  |  | import {XHRImpl} from '../../src/xhr/xhr_impl'; | 
					
						
							|  |  |  | import {PromiseWrapper} from '../../src/facade/async'; | 
					
						
							|  |  |  | import {IS_DART} from '../../src/facade/lang'; | 
					
						
							| 
									
										
										
										
											2015-05-27 13:48:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('XHRImpl', () => { | 
					
						
							| 
									
										
										
										
											2015-06-11 18:50:41 -07:00
										 |  |  |     var xhr: XHRImpl; | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // TODO(juliemr): This file currently won't work with dart unit tests run using
 | 
					
						
							|  |  |  |     // exclusive it or describe (iit or ddescribe). This is because when
 | 
					
						
							|  |  |  |     // pub run test is executed against this specific file the relative paths
 | 
					
						
							|  |  |  |     // will be relative to here, so url200 should look like
 | 
					
						
							|  |  |  |     // static_assets/200.html.
 | 
					
						
							|  |  |  |     // We currently have no way of detecting this.
 | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  |     var urlBase = IS_DART ? '' : '/base/modules/@angular/'; | 
					
						
							| 
									
										
										
										
											2016-05-19 14:31:21 -07:00
										 |  |  |     var url200 = urlBase + 'platform-browser/test/browser/static_assets/200.html'; | 
					
						
							| 
									
										
										
										
											2016-02-10 16:54:32 -08:00
										 |  |  |     var url404 = '/bad/path/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
										 |  |  |   }); | 
					
						
							|  |  |  | } |