| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; | 
					
						
							|  |  |  | import {XHRImpl} from '../../src/xhr/xhr_impl'; | 
					
						
							| 
									
										
										
										
											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-05-20 16:11:49 -07:00
										 |  |  |     var url200 = '/base/modules/@angular/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', | 
					
						
							| 
									
										
										
										
											2016-06-09 11:04:15 -07:00
										 |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2015-05-27 13:48:24 -07:00
										 |  |  |          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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     it('should reject the Promise on failure', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |          xhr.get(url404).catch((e) => { | 
					
						
							| 
									
										
										
										
											2015-05-27 13:48:24 -07:00
										 |  |  |            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
										 |  |  |   }); | 
					
						
							|  |  |  | } |