mirror of
https://github.com/hanzoai/core-js.git
synced 2026-09-24 16:58:15 +00:00
35 lines
1.6 KiB
JavaScript
35 lines
1.6 KiB
JavaScript
import { STRICT } from '../helpers/constants.js';
|
|
import { createIterator } from '../helpers/helpers.js';
|
|
|
|
QUnit.test('Iterator#drop', assert => {
|
|
const { drop } = Iterator.prototype;
|
|
|
|
assert.isFunction(drop);
|
|
assert.arity(drop, 1);
|
|
assert.name(drop, 'drop');
|
|
assert.looksNative(drop);
|
|
assert.nonEnumerable(Iterator.prototype, 'drop');
|
|
|
|
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 1).toArray(), [2, 3], 'basic functionality');
|
|
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 1.5).toArray(), [2, 3], 'float');
|
|
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 4).toArray(), [], 'big');
|
|
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 0).toArray(), [1, 2, 3], 'zero');
|
|
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), Infinity).toArray(), [], Infinity);
|
|
|
|
if (STRICT) {
|
|
assert.throws(() => drop.call(undefined, 1), TypeError);
|
|
assert.throws(() => drop.call(null, 1), TypeError);
|
|
}
|
|
|
|
assert.throws(() => drop.call({}, 1).next(), TypeError);
|
|
assert.throws(() => drop.call([], 1).next(), TypeError);
|
|
assert.throws(() => drop.call(createIterator([1, 2, 3]), -1), RangeError, 'negative');
|
|
const it = createIterator([1], { return() { this.closed = true; } });
|
|
assert.throws(() => drop.call(it, NaN), RangeError, 'NaN');
|
|
assert.throws(() => drop.call(it, -Infinity), RangeError, '-Infinity');
|
|
assert.throws(() => drop.call(it, 0x20000000000000), RangeError, 'unsafe integer');
|
|
assert.true(it.closed, 'drop closes iterator on validation error');
|
|
// https://issues.chromium.org/issues/336839115
|
|
assert.throws(() => drop.call({ next: null }, 0).next(), TypeError);
|
|
});
|