array.prototype.unshift
Version:
ES spec-compliant `Array.prototype.unshift` shim/polyfill/replacement that works as far down as ES3.
41 lines (29 loc) • 1.38 kB
JavaScript
;
var orig = Array.prototype.unshift;
require('../auto');
var test = require('tape');
var defineProperties = require('define-properties');
var callBind = require('call-bind');
var hasStrictMode = require('has-strict-mode')();
var isEnumerable = Object.prototype.propertyIsEnumerable;
var functionsHaveNames = require('functions-have-names')();
var runTests = require('./tests');
test('shimmed', function (t) {
t.comment('shimmed: ' + (Array.prototype.unshift === orig ? 'no ' : 'yes'));
t.equal(Array.prototype.unshift.length, 1, 'Array#unshift has a length of 1');
t.test('Function name', { skip: !functionsHaveNames }, function (st) {
st.equal(Array.prototype.unshift.name, 'unshift', 'Array#unshift has name "unshift"');
st.end();
});
t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
et.equal(false, isEnumerable.call(Array.prototype, 'unshift'), 'Array#unshift is not enumerable');
et.end();
});
t.test('bad array/this value', { skip: !hasStrictMode }, function (st) {
st['throws'](function () { return Array.prototype.unshift.call(undefined, 'a'); }, TypeError, 'undefined is not an object');
st['throws'](function () { return Array.prototype.unshift.call(null, 'a'); }, TypeError, 'null is not an object');
st.end();
});
runTests(callBind(Array.prototype.unshift), t);
t.end();
});