From c9acc61da92aa46d59962a5204d4a6684fba5d8c Mon Sep 17 00:00:00 2001 From: Bryan Bonnet Date: Sun, 20 May 2018 21:47:28 -0400 Subject: [PATCH] fix(isObservable): Fix throwing error when testing isObservable(null) (#3688) * fix(isObservable): Fix throwing error when testing isObservable(null) * fix(isObservable): Use instanceOf instead * fix(isObservable): Cleanup imports --- spec/util/isObservable-spec.ts | 9 +++++++++ src/internal/util/isObservable.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/util/isObservable-spec.ts b/spec/util/isObservable-spec.ts index 91d7d2ae0a..24fb6f69dc 100644 --- a/spec/util/isObservable-spec.ts +++ b/spec/util/isObservable-spec.ts @@ -23,4 +23,13 @@ describe('isObservable', () => { expect(isObservable(o)).to.be.false; }); + + it('should return false for null', () => { + expect(isObservable(null)).to.be.false; + }); + + it('should return false for a number', () => { + expect(isObservable(1)).to.be.false; + }); + }); diff --git a/src/internal/util/isObservable.ts b/src/internal/util/isObservable.ts index 2bda600928..f3df52485b 100644 --- a/src/internal/util/isObservable.ts +++ b/src/internal/util/isObservable.ts @@ -6,5 +6,5 @@ import { ObservableInput } from '../types'; * @param obj the object to test */ export function isObservable(obj: any): obj is Observable { - return obj && obj instanceof Observable || (typeof obj.lift === 'function' && typeof obj.subscribe === 'function'); + return !!obj && (obj instanceof Observable || (typeof obj.lift === 'function' && typeof obj.subscribe === 'function')); }