diff --git a/source/index.ts b/source/index.ts index 3e72b71..868ec18 100644 --- a/source/index.ts +++ b/source/index.ts @@ -136,7 +136,7 @@ namespace is { // tslint:disable-line:no-namespace export const nullOrUndefined = (value: any): value is null | undefined => null_(value) || undefined(value); export const object = (value: any): value is object => !nullOrUndefined(value) && (function_(value) || isObject(value)); export const iterable = (value: any): value is IterableIterator => !nullOrUndefined(value) && function_(value[Symbol.iterator]); - export const asyncIterable = (value: any): value is AsyncIterableIterator => !nullOrUndefined(Symbol.asyncIterator) && function_(value[Symbol.asyncIterator]); + export const asyncIterable = (value: any): value is AsyncIterableIterator => !nullOrUndefined(value) && function_(value[Symbol.asyncIterator]); export const generator = (value: any): value is Generator => iterable(value) && function_(value.next) && function_(value.throw); export const nativePromise = (value: any): value is Promise => diff --git a/source/tests/test.ts b/source/tests/test.ts index 9ccea39..a2d56ad 100644 --- a/source/tests/test.ts +++ b/source/tests/test.ts @@ -455,14 +455,6 @@ if (isNode8orHigher) { });*/ } -if (isNode10orHigher) { - test('is.asyncIterable', t => { - t.true(m.asyncIterable(Object.create({ - [Symbol.asyncIterator]: () => {} // tslint:disable-line:no-empty - }))); - }); -} - test('is.generator', t => { testType(t, 'generator'); }); @@ -612,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 = [