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.

index.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. var test = require('tape');
  3. var hasPropertyDescriptors = require('../');
  4. var sentinel = {};
  5. test('hasPropertyDescriptors', function (t) {
  6. t.equal(typeof hasPropertyDescriptors, 'function', 'is a function');
  7. t.equal(typeof hasPropertyDescriptors.hasArrayLengthDefineBug, 'function', '`hasArrayLengthDefineBug` property is a function');
  8. var yes = hasPropertyDescriptors();
  9. t.test('property descriptors', { skip: !yes }, function (st) {
  10. var o = { a: sentinel };
  11. st.deepEqual(
  12. Object.getOwnPropertyDescriptor(o, 'a'),
  13. {
  14. configurable: true,
  15. enumerable: true,
  16. value: sentinel,
  17. writable: true
  18. },
  19. 'has expected property descriptor'
  20. );
  21. Object.defineProperty(o, 'a', { enumerable: false, writable: false });
  22. st.deepEqual(
  23. Object.getOwnPropertyDescriptor(o, 'a'),
  24. {
  25. configurable: true,
  26. enumerable: false,
  27. value: sentinel,
  28. writable: false
  29. },
  30. 'has expected property descriptor after [[Define]]'
  31. );
  32. st.end();
  33. });
  34. var arrayBug = hasPropertyDescriptors.hasArrayLengthDefineBug();
  35. t.test('defining array lengths', { skip: !yes || arrayBug }, function (st) {
  36. var arr = [1, , 3]; // eslint-disable-line no-sparse-arrays
  37. st.equal(arr.length, 3, 'array starts with length 3');
  38. Object.defineProperty(arr, 'length', { value: 5 });
  39. st.equal(arr.length, 5, 'array ends with length 5');
  40. st.end();
  41. });
  42. t.end();
  43. });