Permalink
Cannot retrieve contributors at this time
67 lines (50 sloc)
1.81 KB
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?
codeql-action/node_modules/es-shim-unscopables/test/index.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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(); | |
}); |