diff --git a/packages/core/src/util/lang.ts b/packages/core/src/util/lang.ts index d539183af5..b6631e84d0 100644 --- a/packages/core/src/util/lang.ts +++ b/packages/core/src/util/lang.ts @@ -21,6 +21,7 @@ export function isPromise(obj: any): obj is Promise { * Determine if the argument is an Observable */ export function isObservable(obj: any | Observable): obj is Observable { - // TODO: use Symbol.observable when https://github.com/ReactiveX/rxjs/issues/2415 will be resolved + // TODO: use isObservable once we update pass rxjs 6.1 + // https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#610-2018-05-03 return !!obj && typeof obj.subscribe === 'function'; } diff --git a/packages/core/src/view/provider.ts b/packages/core/src/view/provider.ts index ffd2c3966a..83e046ce53 100644 --- a/packages/core/src/view/provider.ts +++ b/packages/core/src/view/provider.ts @@ -13,6 +13,7 @@ import {TemplateRef} from '../linker/template_ref'; import {ViewContainerRef} from '../linker/view_container_ref'; import {Renderer as RendererV1, Renderer2} from '../render/api'; import {stringify} from '../util'; +import {isObservable} from '../util/lang'; import {createChangeDetectorRef, createInjector, createRendererV1} from './refs'; import {BindingDef, BindingFlags, DepDef, DepFlags, NodeDef, NodeFlags, OutputDef, OutputType, ProviderData, QueryValueType, Services, ViewData, ViewFlags, ViewState, asElementData, asProviderData, shouldCallLifecycleInitHook} from './types'; @@ -138,7 +139,7 @@ export function createDirectiveInstance(view: ViewData, def: NodeDef): any { for (let i = 0; i < def.outputs.length; i++) { const output = def.outputs[i]; const outputObservable = instance[output.propName !]; - if (typeof outputObservable === 'object') { + if (isObservable(outputObservable)) { const subscription = outputObservable.subscribe( eventHandlerClosure(view, def.parent !.nodeIndex, output.eventName)); view.disposables ![def.outputIndex + i] = subscription.unsubscribe.bind(subscription); diff --git a/packages/core/test/linker/integration_spec.ts b/packages/core/test/linker/integration_spec.ts index fca61d50e2..3a6d125297 100644 --- a/packages/core/test/linker/integration_spec.ts +++ b/packages/core/test/linker/integration_spec.ts @@ -347,17 +347,18 @@ function declareTests({useJit}: {useJit: boolean}) { }); it('should display correct error message for uninitialized @Output', () => { - @Directive({selector: '[uninitializedOuput]'}) - class UninitializedOuput { - @Output() customEvent; - doSomething() { - } + @Component({selector: 'my-uninitialized-output', template: '

It works!

'}) + class UninitializedOutputComp { + @Output() customEvent !: EventEmitter; } - TestBed.configureTestingModule({declarations: [MyComp, UninitializedOuput]}); - const template = '

'; + const template = + ''; TestBed.overrideComponent(MyComp, {set: {template}}); - TestBed.createComponent(MyComp).toThrowError('@Output customEvent not initialized in \'UninitializedOuput\'.'); + + TestBed.configureTestingModule({declarations: [MyComp, UninitializedOutputComp]}); + expect(() => TestBed.createComponent(MyComp)) + .toThrowError('@Output customEvent not initialized in \'UninitializedOutputComp\'.'); }); it('should read directives metadata from their binding token', () => {