Skip to content

Commit e49b5a9

Browse files
author
Bryan Bonnet
committed
fix(isObservable): Fix throwing error when testing isObservable(null)
1 parent dc66731 commit e49b5a9

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

spec/util/isObservable-spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ describe('isObservable', () => {
2323

2424
expect(isObservable(o)).to.be.false;
2525
});
26+
27+
it('should return false for null', () => {
28+
expect(isObservable(null)).to.be.false;
29+
});
30+
31+
it('should return false for a number', () => {
32+
expect(isObservable(1)).to.be.false;
33+
});
34+
2635
});

src/internal/util/isObservable.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { Observable } from '../Observable';
22
import { ObservableInput } from '../types';
3+
import { isObject } from 'rxjs/internal/util/isObject';
4+
import { isFunction } from 'util';
35

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

0 commit comments

Comments
 (0)