Skip to content

Commit

Permalink
fix(isObservable): Fix throwing error when testing isObservable(null)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Bonnet committed May 11, 2018
1 parent dc66731 commit 9615ff3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions spec/util/isObservable-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

});
5 changes: 4 additions & 1 deletion src/internal/util/isObservable.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Observable } from '../Observable';
import { ObservableInput } from '../types';
import { isObject } from './isObject';
import { isFunction } from './isFunction';

/**
* Tests to see if the object is an RxJS {@link Observable}
* @param obj the object to test
*/
export function isObservable<T>(obj: any): obj is Observable<T> {
return obj && obj instanceof Observable || (typeof obj.lift === 'function' && typeof obj.subscribe === 'function');
return obj && obj instanceof Observable ||
(isObject(obj) || isFunction(obj)) ? (isFunction(obj.lift) && isFunction(obj.subscribe)) : false;
}

0 comments on commit 9615ff3

Please sign in to comment.