forked from graphql/graphql-js
/
isAsyncIterable-test.js
51 lines (39 loc) · 1.74 KB
/
isAsyncIterable-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { identityFunc } from '../identityFunc';
import { isAsyncIterable } from '../isAsyncIterable';
describe('isAsyncIterable', () => {
it('should return `true` for AsyncIterable', () => {
const asyncIteratable = { [Symbol.asyncIterator]: identityFunc };
expect(isAsyncIterable(asyncIteratable)).to.equal(true);
// istanbul ignore next (Never called and use just as a placeholder)
async function* asyncGeneratorFunc() {
/* do nothing */
}
expect(isAsyncIterable(asyncGeneratorFunc())).to.equal(true);
// But async generator function itself is not iteratable
expect(isAsyncIterable(asyncGeneratorFunc)).to.equal(false);
});
it('should return `false` for all other values', () => {
expect(isAsyncIterable(null)).to.equal(false);
expect(isAsyncIterable(undefined)).to.equal(false);
expect(isAsyncIterable('ABC')).to.equal(false);
expect(isAsyncIterable('0')).to.equal(false);
expect(isAsyncIterable('')).to.equal(false);
expect(isAsyncIterable([])).to.equal(false);
expect(isAsyncIterable(new Int8Array(1))).to.equal(false);
expect(isAsyncIterable({})).to.equal(false);
expect(isAsyncIterable({ iterable: true })).to.equal(false);
const iterator = { [Symbol.iterator]: identityFunc };
expect(isAsyncIterable(iterator)).to.equal(false);
// istanbul ignore next (Never called and use just as a placeholder)
function* generatorFunc() {
/* do nothing */
}
expect(isAsyncIterable(generatorFunc())).to.equal(false);
const invalidAsyncIteratable = {
[Symbol.asyncIterator]: { next: identityFunc },
};
expect(isAsyncIterable(invalidAsyncIteratable)).to.equal(false);
});
});