Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the robustness and strictness of the checks #10

Merged
merged 1 commit into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ module.exports = value => {
}

// eslint-disable-next-line no-use-extend-native/no-use-extend-native
if (value[Symbol.observable] && value === value[Symbol.observable]()) {
return true;
if (typeof Symbol.observable === 'symbol' && typeof value[Symbol.observable] === 'function') {
// eslint-disable-next-line no-use-extend-native/no-use-extend-native
return value === value[Symbol.observable]();
}

if (value['@@observable'] && value === value['@@observable']()) {
return true;
if (typeof value['@@observable'] === 'function') {
return value === value['@@observable']();
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion test.js → test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {of as rxOf} from 'rxjs';
import * as most from 'most';
import {Stream as xstream} from 'xstream';
import {IndefiniteObservable} from 'indefinite-observable';
import isObservable from '.';
import isObservable from '..';

test('main', t => {
t.true(isObservable(zenObservable.of(1)));
Expand Down
20 changes: 20 additions & 0 deletions test/strict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import test from 'ava';
import isObservable from '..';

const fake1 = {'@@observable': true};
const fake2 = {undefined: true};
const fake3 = {
undefined() {
return this;
}
};

test('strict', t => {
// Symbol.observable is defined via AVA
delete Symbol.observable;
// eslint-disable-next-line no-use-extend-native/no-use-extend-native
t.is(Symbol.observable, undefined);
t.false(isObservable(fake1));
t.false(isObservable(fake2));
t.false(isObservable(fake3));
});