-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathes.iterator.to-array.js
28 lines (21 loc) · 998 Bytes
/
es.iterator.to-array.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
import { STRICT } from '../helpers/constants.js';
import { createIterable, createIterator } from '../helpers/helpers.js';
QUnit.test('Iterator#toArray', assert => {
const { toArray } = Iterator.prototype;
assert.isFunction(toArray);
assert.arity(toArray, 0);
assert.name(toArray, 'toArray');
assert.looksNative(toArray);
assert.nonEnumerable(Iterator.prototype, 'toArray');
assert.arrayEqual([1, 2, 3].values().toArray(), [1, 2, 3]);
assert.arrayEqual(new Set([1, 2, 3]).values().toArray(), [1, 2, 3]);
assert.arrayEqual(Iterator.from('123').toArray(), ['1', '2', '3']);
assert.arrayEqual(Iterator.from(createIterable([1, 2, 3])).toArray(), [1, 2, 3]);
assert.arrayEqual(toArray.call(createIterator([1, 2, 3])), [1, 2, 3]);
if (STRICT) {
assert.throws(() => toArray.call(undefined), TypeError);
assert.throws(() => toArray.call(null), TypeError);
}
assert.throws(() => toArray.call({}), TypeError);
assert.throws(() => toArray.call([]), TypeError);
});