index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. var $defineProperty = require('../');
  3. var test = require('tape');
  4. var gOPD = require('gopd');
  5. test('defineProperty: supported', { skip: !$defineProperty }, function (t) {
  6. t.plan(4);
  7. t.equal(typeof $defineProperty, 'function', 'defineProperty is supported');
  8. if ($defineProperty && gOPD) { // this `if` check is just to shut TS up
  9. var o = { a: 1 };
  10. $defineProperty(o, 'b', { enumerable: true, value: 2 });
  11. t.deepEqual(
  12. gOPD(o, 'b'),
  13. {
  14. configurable: false,
  15. enumerable: true,
  16. value: 2,
  17. writable: false
  18. },
  19. 'property descriptor is as expected'
  20. );
  21. $defineProperty(o, 'c', { enumerable: false, value: 3, writable: true });
  22. t.deepEqual(
  23. gOPD(o, 'c'),
  24. {
  25. configurable: false,
  26. enumerable: false,
  27. value: 3,
  28. writable: true
  29. },
  30. 'property descriptor is as expected'
  31. );
  32. }
  33. t.equal($defineProperty, Object.defineProperty, 'defineProperty is Object.defineProperty');
  34. t.end();
  35. });
  36. test('defineProperty: not supported', { skip: !!$defineProperty }, function (t) {
  37. t.notOk($defineProperty, 'defineProperty is not supported');
  38. t.match(
  39. typeof $defineProperty,
  40. /^(?:undefined|boolean)$/,
  41. '`typeof defineProperty` is `undefined` or `boolean`'
  42. );
  43. t.end();
  44. });