You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.3 KiB

4 years ago
  1. 'use strict';
  2. var getDescriptors = require('../');
  3. getDescriptors.shim();
  4. var test = require('tape');
  5. var defineProperties = require('define-properties');
  6. var runTests = require('./tests');
  7. var isEnumerable = Object.prototype.propertyIsEnumerable;
  8. var functionsHaveNames = function f() {}.name === 'f';
  9. test('shimmed', function (t) {
  10. t.equal(Object.getOwnPropertyDescriptors.length, 1, 'Object.getOwnPropertyDescriptors has a length of 1');
  11. t.test('Function name', { skip: !functionsHaveNames }, function (st) {
  12. st.equal(Object.getOwnPropertyDescriptors.name, 'getOwnPropertyDescriptors', 'Object.getOwnPropertyDescriptors has name "getOwnPropertyDescriptors"');
  13. st.end();
  14. });
  15. t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
  16. et.equal(false, isEnumerable.call(Object, 'getOwnPropertyDescriptors'), 'Object.getOwnPropertyDescriptors is not enumerable');
  17. et.end();
  18. });
  19. var supportsStrictMode = (function () { return typeof this === 'undefined'; }());
  20. t.test('bad object/this value', { skip: !supportsStrictMode }, function (st) {
  21. st.throws(function () { return getDescriptors(undefined, 'a'); }, TypeError, 'undefined is not an object');
  22. st.throws(function () { return getDescriptors(null, 'a'); }, TypeError, 'null is not an object');
  23. st.end();
  24. });
  25. runTests(Object.getOwnPropertyDescriptors, t);
  26. t.end();
  27. });