Skip to content

Commit

Permalink
Improve the robustness and strictness of the checks (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
chocolateboy authored Aug 2, 2020
1 parent ca9746c commit e02e7f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
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));
});

0 comments on commit e02e7f2

Please sign in to comment.