2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, inject,} from '@angular/core/testing/testing_internal';
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-05 14:58:24 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {SpyChangeDetectorRef} from '../spies';
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {isBlank} from '../../src/facade/lang';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {AsyncPipe} from '@angular/common';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {WrappedValue} from '@angular/core';
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {EventEmitter, ObservableWrapper, PromiseWrapper, TimerWrapper} from '../../src/facade/async';
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {PromiseCompleter} from '../../src/facade/promise';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {browserDetection} from '@angular/platform-browser/testing';
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export function main() {
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  describe('AsyncPipe', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe('Observable', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-17 10:57:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      var emitter: EventEmitter<any>;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      var pipe: AsyncPipe;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      var ref: any;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      var message = {};
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      beforeEach(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        emitter = new EventEmitter();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ref = new SpyChangeDetectorRef();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        pipe = new AsyncPipe(ref);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      describe('transform', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        it('should return null when subscribing to an observable',
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           () => { expect(pipe.transform(emitter)).toBe(null); });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should return the latest available value wrapped',
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-09 11:04:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             pipe.transform(emitter);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-15 23:58:59 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             ObservableWrapper.callEmit(emitter, message);
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             TimerWrapper.setTimeout(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               expect(pipe.transform(emitter)).toEqual(new WrappedValue(message));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               async.done();
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-25 17:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             }, 0)
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-25 17:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should return same value when nothing has changed since the last call',
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-09 11:04:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             pipe.transform(emitter);
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-15 23:58:59 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             ObservableWrapper.callEmit(emitter, message);
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             TimerWrapper.setTimeout(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               pipe.transform(emitter);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               expect(pipe.transform(emitter)).toBe(message);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               async.done();
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-25 17:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             }, 0)
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should dispose of the existing subscription when subscribing to a new observable',
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-09 11:04:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             pipe.transform(emitter);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             var newEmitter = new EventEmitter();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             expect(pipe.transform(newEmitter)).toBe(null);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             // this should not affect the pipe
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-15 23:58:59 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             ObservableWrapper.callEmit(emitter, message);
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             TimerWrapper.setTimeout(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               expect(pipe.transform(newEmitter)).toBe(null);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               async.done();
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-25 17:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             }, 0)
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should request a change detection check upon receiving a new value',
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-09 11:04:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             pipe.transform(emitter);
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-15 23:58:59 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             ObservableWrapper.callEmit(emitter, message);
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             TimerWrapper.setTimeout(() => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-28 10:08:18 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               expect(ref.spy('markForCheck')).toHaveBeenCalled();
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               async.done();
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-25 17:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             }, 10)
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      describe('ngOnDestroy', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        it('should do nothing when no subscription',
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-17 10:09:23 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           () => { expect(() => pipe.ngOnDestroy()).not.toThrow(); });
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should dispose of the existing subscription',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             pipe.transform(emitter);
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-17 10:09:23 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             pipe.ngOnDestroy();
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-15 23:58:59 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             ObservableWrapper.callEmit(emitter, message);
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             TimerWrapper.setTimeout(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               expect(pipe.transform(emitter)).toBe(null);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               async.done();
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-25 17:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             }, 0)
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    describe('Promise', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      var message = new Object();
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-19 11:49:31 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      var pipe: AsyncPipe;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      var completer: PromiseCompleter<any>;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      var ref: SpyChangeDetectorRef;
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      // adds longer timers for passing tests in IE
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      var timer = (!isBlank(getDOM()) && browserDetection.isIE) ? 50 : 10;
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      beforeEach(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        completer = PromiseWrapper.completer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ref = new SpyChangeDetectorRef();
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-19 11:49:31 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        pipe = new AsyncPipe(<any>ref);
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      describe('transform', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        it('should return null when subscribing to a promise',
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           () => { expect(pipe.transform(completer.promise)).toBe(null); });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should return the latest available value',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             pipe.transform(completer.promise);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             completer.resolve(message);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             TimerWrapper.setTimeout(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               async.done();
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-25 17:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             }, timer)
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should return unwrapped value when nothing has changed since the last call',
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-09 11:04:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             pipe.transform(completer.promise);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             completer.resolve(message);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             TimerWrapper.setTimeout(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               pipe.transform(completer.promise);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               expect(pipe.transform(completer.promise)).toBe(message);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               async.done();
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-25 17:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             }, timer)
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should dispose of the existing subscription when subscribing to a new promise',
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-09 11:04:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             pipe.transform(completer.promise);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             var newCompleter = PromiseWrapper.completer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             expect(pipe.transform(newCompleter.promise)).toBe(null);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             // this should not affect the pipe, so it should return WrappedValue
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             completer.resolve(message);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             TimerWrapper.setTimeout(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               expect(pipe.transform(newCompleter.promise)).toBe(null);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               async.done();
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-25 17:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             }, timer)
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should request a change detection check upon receiving a new value',
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-09 11:04:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-25 14:24:17 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var markForCheck = ref.spy('markForCheck');
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             pipe.transform(completer.promise);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             completer.resolve(message);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             TimerWrapper.setTimeout(() => {
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-25 14:24:17 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               expect(markForCheck).toHaveBeenCalled();
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               async.done();
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-25 17:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             }, timer)
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        describe('ngOnDestroy', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          it('should do nothing when no source',
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-17 10:09:23 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             () => { expect(() => pipe.ngOnDestroy()).not.toThrow(); });
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          it('should dispose of the existing source',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               pipe.transform(completer.promise);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               expect(pipe.transform(completer.promise)).toBe(null);
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-25 17:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               completer.resolve(message)
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               TimerWrapper.setTimeout(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                 expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                 pipe.ngOnDestroy();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                 expect(pipe.transform(completer.promise)).toBe(null);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                 async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               }, timer);
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe('null', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it('should return null when given null', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        var pipe = new AsyncPipe(null);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-22 15:33:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(pipe.transform(null)).toEqual(null);
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe('other types', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it('should throw when given an invalid object', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        var pipe = new AsyncPipe(null);
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(() => pipe.transform(<any>'some bogus object')).toThrowError();
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-04 11:55:21 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |