shimmed.js 1.6 KB

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