shimmed.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. var fromEntries = require('../');
  3. fromEntries.shim();
  4. var test = require('tape');
  5. var keys = require('object-keys');
  6. var defineProperties = require('define-properties');
  7. var isEnumerable = Object.prototype.propertyIsEnumerable;
  8. var functionsHaveNames = function f() {}.name === 'f';
  9. var runTests = require('./tests');
  10. test('shimmed', function (t) {
  11. t.equal(Object.fromEntries.length, 1, 'Object.fromEntries has a length of 1');
  12. t.test('Function name', { skip: !functionsHaveNames }, function (st) {
  13. st.equal(Object.fromEntries.name, 'fromEntries', 'Object.fromEntries has name "fromEntries"');
  14. st.end();
  15. });
  16. t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
  17. et.equal(false, isEnumerable.call(Object, 'fromEntries'), 'Object.fromEntries is not enumerable');
  18. et.end();
  19. });
  20. var supportsStrictMode = (function () { return typeof this === 'undefined'; }());
  21. t.test('bad object value', { skip: !supportsStrictMode }, function (st) {
  22. st['throws'](function () { return Object.fromEntries(undefined); }, TypeError, 'undefined is not an object');
  23. st['throws'](function () { return Object.fromEntries(null); }, TypeError, 'null is not an object');
  24. st.end();
  25. });
  26. t.test('does not mutate global method', function (st) {
  27. st.deepEqual(keys(Object.fromEntries), [], 'no enumerable keys');
  28. st.equal('shim' in Object.fromEntries, false, '"shim" is not present');
  29. st.equal('getPolyfill' in Object.fromEntries, false, '"getPolyfill" is not present');
  30. st.equal('implementation' in Object.fromEntries, false, '"implementation" is not present');
  31. st.end();
  32. });
  33. runTests(Object.fromEntries, t);
  34. t.end();
  35. });