forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.array.some.js
38 lines (37 loc) · 1.36 KB
/
es.array.some.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
37
38
import { STRICT } from '../helpers/constants';
QUnit.test('Array#some', assert => {
const { some } = Array.prototype;
assert.isFunction(some);
assert.arity(some, 1);
assert.name(some, 'some');
assert.looksNative(some);
assert.nonEnumerable(Array.prototype, 'some');
let array = [1];
const context = {};
array.some(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([1, '2', 3].some(value => typeof value === 'number'));
assert.ok([1, 2, 3].some(value => value < 3));
assert.ok(![1, 2, 3].some(value => value < 0));
assert.ok(![1, 2, 3].some(value => typeof value === 'string'));
assert.ok(![1, 2, 3].some(function () {
return +this !== 1;
}, 1));
let result = '';
[1, 2, 3].some((value, key) => {
result += key;
return false;
});
assert.ok(result === '012');
array = [1, 2, 3];
assert.ok(!array.some((value, key, that) => that !== array));
if (STRICT) {
assert.throws(() => some.call(null, () => { /* empty */ }), TypeError);
assert.throws(() => some.call(undefined, () => { /* empty */ }), TypeError);
}
});