| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  | import {describe, it, expect, beforeEach, ddescribe, iit, xit, el, | 
					
						
							|  |  |  |   SpyObject, AsyncTestCompleter, inject, IS_DARTIUM} from 'angular2/test_lib'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  | import {ObservableWrapper, EventEmitter, PromiseWrapper} from 'angular2/src/facade/async'; | 
					
						
							| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  |   describe('EventEmitter', () => { | 
					
						
							|  |  |  |     var emitter:EventEmitter; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  |     beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  |       emitter = new EventEmitter(); | 
					
						
							| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should call the next callback",  inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  |       ObservableWrapper.subscribe(emitter, (value) => { | 
					
						
							| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  |         expect(value).toEqual(99); | 
					
						
							|  |  |  |         async.done(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  |       ObservableWrapper.callNext(emitter, 99); | 
					
						
							| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  |     })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should call the throw callback", inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  |       ObservableWrapper.subscribe(emitter, (_) => {}, (error) => { | 
					
						
							| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  |         expect(error).toEqual("Boom"); | 
					
						
							|  |  |  |         async.done(); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  |       ObservableWrapper.callThrow(emitter, "Boom"); | 
					
						
							|  |  |  |     })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should work when no throw callback is provided", inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |       ObservableWrapper.subscribe(emitter, (_) => {}, (_) => { | 
					
						
							|  |  |  |         async.done(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       ObservableWrapper.callThrow(emitter, "Boom"); | 
					
						
							| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  |     })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should call the return callback", inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  |       ObservableWrapper.subscribe(emitter, (_) => {}, (_) => {}, () => { | 
					
						
							| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  |         async.done(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  |       ObservableWrapper.callReturn(emitter); | 
					
						
							| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  |     })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should subscribe to the wrapper asynchronously", () => { | 
					
						
							|  |  |  |       var called = false; | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  |       ObservableWrapper.subscribe(emitter, (value) => { | 
					
						
							| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  |         called = true; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  |       ObservableWrapper.callNext(emitter, 99); | 
					
						
							| 
									
										
										
										
											2015-03-24 13:45:39 -07:00
										 |  |  |       expect(called).toBe(false); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //TODO: vsavkin: add tests cases
 | 
					
						
							|  |  |  |     //should call dispose on the subscription if generator returns {done:true}
 | 
					
						
							|  |  |  |     //should call dispose on the subscription on throw
 | 
					
						
							|  |  |  |     //should call dispose on the subscription on return
 | 
					
						
							|  |  |  |  }); | 
					
						
							| 
									
										
										
										
											2015-04-14 14:34:41 -07:00
										 |  |  | } |