Add is.asyncIterable (#59)

This commit is contained in:
Artur Androsovych 2018-07-09 20:35:16 +03:00 committed by Sindre Sorhus
parent c84c2cbeca
commit c8736c2972
4 changed files with 20 additions and 1 deletions

View file

@ -10,6 +10,7 @@ import ZenObservable from 'zen-observable';
import m from '..';
const isNode8orHigher = Number(process.versions.node.split('.')[0]) >= 8;
const isNode10orHigher = Number(process.versions.node.split('.')[0]) >= 10;
class PromiseSubclassFixture<T> extends Promise<T> {}
class ErrorSubclassFixture extends Error {}
@ -603,6 +604,21 @@ test('is.iterable', t => {
t.false(m.iterable({}));
});
if (isNode10orHigher) {
test('is.asyncIterable', t => {
t.true(m.asyncIterable({
[Symbol.asyncIterator]: () => {} // tslint:disable-line:no-empty
}));
t.false(m.asyncIterable(null));
t.false(m.asyncIterable(undefined));
t.false(m.asyncIterable(0));
t.false(m.asyncIterable(NaN));
t.false(m.asyncIterable(Infinity));
t.false(m.asyncIterable({}));
});
}
test('is.class', t => {
class Foo {} // tslint:disable-line
const classDeclarations = [