forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.array.every.js
32 lines (30 loc) · 1.2 KB
/
es.array.every.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
import { STRICT } from '../helpers/constants';
import every from 'core-js-pure/features/array/every';
QUnit.test('Array#every', assert => {
assert.isFunction(every);
const array = [1];
const context = {};
every(array, function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 0, 'correct index in callback');
assert.same(that, array, 'correct link to array in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.ok(every([1, 2, 3], it => typeof it === 'number'));
assert.ok(every([1, 2, 3], it => it < 4));
assert.ok(!every([1, 2, 3], it => it < 3));
assert.ok(!every([1, 2, 3], it => typeof it === 'string'));
assert.ok(every([1, 2, 3], function () {
return +this === 1;
}, 1));
let rez = '';
every([1, 2, 3], (value, key) => rez += key);
assert.ok(rez === '012');
const arr = [1, 2, 3];
assert.ok(every(arr, (value, key, that) => that === arr));
if (STRICT) {
assert.throws(() => every(null, () => { /* empty */ }), TypeError);
assert.throws(() => every(undefined, () => { /* empty */ }), TypeError);
}
});