Skip to content

fix(isObservable): Fix throwing error when testing isObservable(null)#3688

Merged
benlesh merged 3 commits intoReactiveX:masterfrom
bbonnet:fix-isObservable
May 21, 2018
Merged

fix(isObservable): Fix throwing error when testing isObservable(null)#3688
benlesh merged 3 commits intoReactiveX:masterfrom
bbonnet:fix-isObservable

Conversation

@bbonnet
Copy link
Contributor

@bbonnet bbonnet commented May 11, 2018

Description:
Fix isObservable to test to make sure the test subject is a function or object before attempting to access properties on it.

Related issue (if exists):
#3687

@bbonnet bbonnet force-pushed the fix-isObservable branch from e49b5a9 to 9615ff3 Compare May 11, 2018 16:18
@coveralls
Copy link

coveralls commented May 11, 2018

Coverage Status

Coverage decreased (-0.2%) to 96.629% when pulling f866d24 on bbonnet:fix-isObservable into dc66731 on ReactiveX:master.

Copy link
Member

@benlesh benlesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite right. We don't need to check to see if it's a function or object, we just needed to group the checks after the "falsiness" check.

return obj && (obj instanceof Observable || (typeof obj.lift === 'function' && typeof obj.subscribe === 'function'))

@bbonnet
Copy link
Contributor Author

bbonnet commented May 15, 2018

@benlesh Above suggestion gave me AssertionError: expected null to be false for the isObservable(null) case so added !!obj for coercion to boolean

import { Observable } from '../Observable';
import { ObservableInput } from '../types';
import { isObject } from './isObject';
import { isFunction } from './isFunction';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, updated.

@benlesh benlesh merged commit c9acc61 into ReactiveX:master May 21, 2018
@benlesh
Copy link
Member

benlesh commented May 21, 2018

thanks @bbonnet!

@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants