-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
esnext.async-iterator.from.js
33 lines (25 loc) · 1.13 KB
/
esnext.async-iterator.from.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
import Promise from 'core-js-pure/es/promise';
import assign from 'core-js-pure/es/object/assign';
import values from 'core-js-pure/es/array/values';
import AsyncIterator from 'core-js-pure/full/async-iterator';
QUnit.test('AsyncIterator.from', assert => {
assert.expect(10);
const async = assert.async();
const { from } = AsyncIterator;
assert.isFunction(from);
assert.arity(from, 1);
assert.true(AsyncIterator.from(values([])) instanceof AsyncIterator, 'proxy, iterator');
assert.true(AsyncIterator.from([]) instanceof AsyncIterator, 'proxy, iterable');
AsyncIterator.from([1, Promise.resolve(2), 3]).toArray().then(result => {
assert.arrayEqual(result, [1, 2, 3], 'unwrap promises');
async();
});
const asyncIterator = assign(new AsyncIterator(), {
next: () => { /* empty */ },
});
assert.same(AsyncIterator.from(asyncIterator), asyncIterator, 'does not wrap AsyncIterator instances');
assert.throws(() => from(undefined), TypeError);
assert.throws(() => from(null), TypeError);
assert.throws(() => from({}), TypeError);
assert.throws(() => from(assign(new AsyncIterator(), { next: 42 })), TypeError);
});