Skip to content
Permalink
9bfb9ba527
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
67 lines (50 sloc) 1.81 KB
'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();
});