UNPKG

array.prototype.splice

Version:

An ES5 spec-compliant `Array.prototype.splice` shim/polyfill/replacement that works as far down as ES3.

37 lines (27 loc) 1.25 kB
'use strict'; 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.equal(Array.prototype.splice.length, 2, 'Array#splice has a length of 2'); t.test('Function name', { skip: !functionsHaveNames }, function (st) { st.equal(Array.prototype.splice.name, 'splice', 'Array#splice has name "splice"'); st.end(); }); t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) { et.equal(false, isEnumerable.call(Array.prototype, 'splice'), 'Array#splice is not enumerable'); et.end(); }); t.test('bad array/this value', { skip: !hasStrictMode }, function (st) { st['throws'](function () { return Array.prototype.splice.call(undefined, 'a'); }, TypeError, 'undefined is not an object'); st['throws'](function () { return Array.prototype.splice.call(null, 'a'); }, TypeError, 'null is not an object'); st.end(); }); runTests(callBind(Array.prototype.splice), t); t.end(); });