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
…#3688)

* fix(isObservable): Fix throwing error when testing isObservable(null)

* fix(isObservable): Use instanceOf instead

* fix(isObservable): Cleanup imports
  • Loading branch information
bbonnet authored and benlesh committed May 21, 2018
1 parent 537fe7d commit c9acc61
Show file tree
Hide file tree
Showing 2 changed files with 10 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;
});

});
2 changes: 1 addition & 1 deletion src/internal/util/isObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import { ObservableInput } from '../types';
* @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 || (typeof obj.lift === 'function' && typeof obj.subscribe === 'function'));
}

0 comments on commit c9acc61

Please sign in to comment.