shimmed.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. var orig = Array.prototype.includes;
  3. require('../auto');
  4. var test = require('tape');
  5. var defineProperties = require('define-properties');
  6. var bind = require('function-bind');
  7. var isEnumerable = Object.prototype.propertyIsEnumerable;
  8. var functionsHaveNames = require('functions-have-names')();
  9. var runTests = require('./tests');
  10. test('shimmed', function (t) {
  11. t.comment('shimmed: ' + (orig === Array.prototype.includes ? 'no' : 'yes'));
  12. t.equal(Array.prototype.includes.length, 1, 'Array#includes has a length of 1');
  13. t.test('Function name', { skip: !functionsHaveNames }, function (st) {
  14. st.equal(Array.prototype.includes.name, 'includes', 'Array#includes has name "includes"');
  15. st.end();
  16. });
  17. t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
  18. et.equal(false, isEnumerable.call(Array.prototype, 'includes'), 'Array#includes is not enumerable');
  19. et.end();
  20. });
  21. var supportsStrictMode = (function () { return typeof this === 'undefined'; }());
  22. t.test('bad array/this value', { skip: !supportsStrictMode }, function (st) {
  23. st['throws'](function () { return Array.prototype.includes.call(undefined, 'a'); }, TypeError, 'undefined is not an object');
  24. st['throws'](function () { return Array.prototype.includes.call(null, 'a'); }, TypeError, 'null is not an object');
  25. st.end();
  26. });
  27. runTests(bind.call(Function.call, Array.prototype.includes), t);
  28. t.end();
  29. });