index.js
1.81 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
var test = require('tape');
var inspect = require('object-inspect');
var v = require('es-value-fixtures');
var forEach = require('for-each');
var has = require('has');
var shimUnscopables = require('../');
var sortSymbols = function (a, b) {
return inspect(a).localeCompare(inspect(b));
};
test('shimUnscopables', function (t) {
t.equal(typeof shimUnscopables, 'function', 'is a function');
forEach(v.nonStrings, function (notNonEmptyString) {
t['throws'](
function () { shimUnscopables(notNonEmptyString); },
TypeError,
inspect(notNonEmptyString) + ' is not a non-empty String'
);
});
t['throws'](
function () { shimUnscopables('x'); },
TypeError,
inspect('x') + ' is not on Array.prototype'
);
t.test('no symbols', { skip: typeof Symbol === 'function' }, function (st) {
st.doesNotThrow(function () { shimUnscopables('forEach'); });
st.end();
});
t.test('symbols, no unscopables', { skip: typeof Symbol !== 'function' || Symbol.unscopables }, function (st) {
st.deepEqual(Object.getOwnPropertySymbols(Array.prototype), [Symbol.iterator]);
shimUnscopables('forEach');
st.deepEqual(Object.getOwnPropertySymbols(Array.prototype), [Symbol.iterator]);
st.end();
});
t.test('Symbol.unscopables', { skip: typeof Symbol !== 'function' || !Symbol.unscopables }, function (st) {
st.deepEqual(
Object.getOwnPropertySymbols(Array.prototype).sort(sortSymbols),
[Symbol.iterator, Symbol.unscopables]
);
st.notOk(has(Array.prototype[Symbol.unscopables], 'forEach'), 'unscopables map lacks forEach');
shimUnscopables('forEach');
st.deepEqual(
Object.getOwnPropertySymbols(Array.prototype).sort(sortSymbols),
[Symbol.iterator, Symbol.unscopables]
);
st.equal(Array.prototype[Symbol.unscopables].forEach, true, 'unscopables map has forEach');
st.end();
});
t.end();
});