Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
QUnit.test('AsyncIterator#map', assert => {
assert.expect(15);
const async = assert.async();
const { map } = AsyncIterator.prototype;
assert.isFunction(map);
assert.arity(map, 1);
assert.nonEnumerable(AsyncIterator.prototype, 'map');
map.call(createIterator([1, 2, 3]), it => it ** 2).toArray().then(it => {
assert.arrayEqual(it, [1, 4, 9], 'basic functionality');
return map.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
}).toArray();
}).then(() => {
return map.call(createIterator([1]), () => { throw 42; }).toArray();
}).catch(error => {
assert.same(error, 42, 'rejection on a callback error');
}).then(() => async());
assert.throws(() => map.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => map.call(null, () => { /* empty */ }), TypeError);QUnit.test('AsyncIterator#reduce', assert => {
assert.expect(18);
const async = assert.async();
const { reduce } = AsyncIterator.prototype;
assert.isFunction(reduce);
assert.arity(reduce, 1);
assert.nonEnumerable(AsyncIterator.prototype, 'reduce');
reduce.call(createIterator([1, 2, 3]), (a, b) => a + b, 1).then(it => {
assert.same(it, 7, 'basic functionality, initial');
return reduce.call(createIterator([2]), function (a, b) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 2, 'arguments length');
assert.same(a, 1, 'argument 1');
assert.same(b, 2, 'argument 2');
}, 1);
}).then(() => {
return reduce.call(createIterator([1, 2, 3]), (a, b) => a + b);
}).then(it => {QUnit.test('AsyncIterator#every', assert => {
assert.expect(16);
const async = assert.async();
const { every } = AsyncIterator.prototype;
assert.isFunction(every);
assert.arity(every, 1);
assert.nonEnumerable(AsyncIterator.prototype, 'every');
every.call(createIterator([1, 2, 3]), it => typeof it === 'number').then(result => {
assert.ok(result, 'basic functionality, +');
return every.call(createIterator([1, 2, 3]), it => it === 2);
}).then(result => {
assert.ok(!result, 'basic functionality, -');
return every.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});
}).then(() => {
return every.call(createIterator([1]), () => { throw 42; });
}).catch(error => {
assert.same(error, 42, 'rejection on a callback error');
}).then(() => async());QUnit.test('AsyncIterator#forEach', assert => {
assert.expect(15);
const async = assert.async();
const { forEach } = AsyncIterator.prototype;
assert.isFunction(forEach);
assert.arity(forEach, 1);
assert.nonEnumerable(AsyncIterator.prototype, 'forEach');
const array = [];
forEach.call(createIterator([1, 2, 3]), it => array.push(it)).then(() => {
assert.arrayEqual(array, [1, 2, 3], 'basic functionality');
return forEach.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});
}).then(() => {
return forEach.call(createIterator([1]), () => { throw 42; });
}).catch(error => {
assert.same(error, 42, 'rejection on a callback error');
}).then(() => async());QUnit.test('AsyncIterator#take', assert => {
assert.expect(12);
const async = assert.async();
const { take } = AsyncIterator.prototype;
assert.isFunction(take);
assert.arity(take, 1);
assert.nonEnumerable(AsyncIterator.prototype, 'take');
take.call(createIterator([1, 2, 3]), 2).toArray().then(it => {
assert.arrayEqual(it, [1, 2], 'basic functionality');
return take.call(createIterator([1, 2, 3]), 1.5).toArray();
}).then(it => {
assert.arrayEqual(it, [1], 'float');
return take.call(createIterator([1, 2, 3]), 4).toArray();
}).then(it => {
assert.arrayEqual(it, [1, 2, 3], 'big');
return take.call(createIterator([1, 2, 3]), 0).toArray();
}).then(it => {
assert.arrayEqual(it, [], 'zero');QUnit.test('AsyncIterator#map', assert => {
assert.expect(15);
const async = assert.async();
const { map } = AsyncIterator.prototype;
assert.isFunction(map);
assert.arity(map, 1);
assert.nonEnumerable(AsyncIterator.prototype, 'map');
map.call(createIterator([1, 2, 3]), it => it ** 2).toArray().then(it => {
assert.arrayEqual(it, [1, 4, 9], 'basic functionality');
return map.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
}).toArray();
}).then(() => {
return map.call(createIterator([1]), () => { throw 42; }).toArray();
}).catch(error => {
assert.same(error, 42, 'rejection on a callback error');QUnit.test('AsyncIterator#some', assert => {
assert.expect(16);
const async = assert.async();
const { some } = AsyncIterator.prototype;
assert.isFunction(some);
assert.arity(some, 1);
assert.nonEnumerable(AsyncIterator.prototype, 'some');
some.call(createIterator([1, 2, 3]), it => it === 2).then(result => {
assert.ok(result, 'basic functionality, +');
return some.call(createIterator([1, 2, 3]), it => it === 4);
}).then(result => {
assert.ok(!result, 'basic functionality, -');
return some.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});
}).then(() => {
return some.call(createIterator([1]), () => { throw 42; });
}).catch(error => {
assert.same(error, 42, 'rejection on a callback error');
}).then(() => async());QUnit.test('AsyncIterator#constructor', assert => {
assert.strictEqual(AsyncIterator.prototype.constructor, AsyncIterator, 'AsyncIterator#constructor is AsyncIterator');
});QUnit.test('AsyncIterator#flatMap', assert => {
assert.expect(15);
const async = assert.async();
const { flatMap } = AsyncIterator.prototype;
assert.isFunction(flatMap);
assert.arity(flatMap, 1);
assert.nonEnumerable(AsyncIterator.prototype, 'flatMap');
flatMap.call(createIterator([1, [], 2, createIterable([3, 4]), [5, 6], 'ab']), it => typeof it == 'number' ? [-it] : it).toArray().then(it => {
assert.arrayEqual(it, [-1, -2, 3, 4, 5, 6, 'a', 'b'], 'basic functionality');
return flatMap.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
return [arg];
}).toArray();
}).then(() => {
return flatMap.call(createIterator([1]), () => { throw 42; }).toArray();
}).catch(error => {QUnit.test('AsyncIterator#every', assert => {
assert.expect(16);
const async = assert.async();
const { every } = AsyncIterator.prototype;
assert.isFunction(every);
assert.arity(every, 1);
assert.nonEnumerable(AsyncIterator.prototype, 'every');
every.call(createIterator([1, 2, 3]), it => typeof it === 'number').then(result => {
assert.ok(result, 'basic functionality, +');
return every.call(createIterator([1, 2, 3]), it => it === 2);
}).then(result => {
assert.ok(!result, 'basic functionality, -');
return every.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});
}).then(() => {