/
esnext.async-iterator.filter.js
36 lines (31 loc) · 1.54 KB
/
esnext.async-iterator.filter.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
import { createIterator } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';
import AsyncIterator from 'core-js-pure/full/async-iterator';
QUnit.test('AsyncIterator#filter', assert => {
assert.expect(16);
const async = assert.async();
const { filter } = AsyncIterator.prototype;
assert.isFunction(filter);
assert.arity(filter, 1);
assert.nonEnumerable(AsyncIterator.prototype, 'filter');
filter.call(createIterator([1, 2, 3]), it => it % 2).toArray().then(it => {
assert.arrayEqual(it, [1, 3], 'basic functionality');
return filter.call(createIterator([1]), function (arg, counter) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 2, 'arguments length');
assert.same(arg, 1, 'argument');
assert.same(counter, 0, 'counter');
}).toArray();
}).then(() => {
return filter.call(createIterator([1]), () => { throw 42; }).toArray();
}).catch(error => {
assert.same(error, 42, 'rejection on a callback error');
}).then(() => async());
assert.throws(() => filter.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => filter.call(null, () => { /* empty */ }), TypeError);
assert.throws(() => filter.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => filter.call([], () => { /* empty */ }), TypeError);
assert.throws(() => filter.call(createIterator([1]), undefined), TypeError);
assert.throws(() => filter.call(createIterator([1]), null), TypeError);
assert.throws(() => filter.call(createIterator([1]), {}), TypeError);
});