index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict';
  2. var test = require('tape');
  3. var isDescriptor = require('../');
  4. var noop = function () {};
  5. test('isDescriptor', function (t) {
  6. t.test('value type', function (st) {
  7. st.notOk(isDescriptor('a'), 'string is not a descriptor');
  8. st.notOk(isDescriptor(null), 'null is not a descriptor');
  9. st.end();
  10. });
  11. t.test('should not be false when the object has unknown properties:', function (st) {
  12. st.ok(isDescriptor({ value: 'foo', bar: 'baz' }));
  13. st.ok(isDescriptor({ value: 'foo', bar: 'baz' }));
  14. st.end();
  15. });
  16. t.test('should be false when the object has accessor properties', function (st) {
  17. st.notOk(isDescriptor({ value: 'foo', get: noop }));
  18. st.notOk(isDescriptor({ set: noop, value: noop }));
  19. st.end();
  20. });
  21. t.test('should be true when the object has valid data-descriptor properties', function (st) {
  22. st.ok(isDescriptor({ value: 'foo' }));
  23. st.ok(isDescriptor({ value: noop }));
  24. st.end();
  25. });
  26. t.test('should be false when valid properties are invalid types', function (st) {
  27. st.notOk(isDescriptor({ value: 'foo', enumerable: 'foo' }));
  28. st.notOk(isDescriptor({ value: 'foo', configurable: 'foo' }));
  29. st.notOk(isDescriptor({ value: 'foo', writable: 'foo' }));
  30. st.end();
  31. });
  32. t.test('should be true when a value is a valid data descriptor', function (st) {
  33. st.ok(isDescriptor({ value: 'foo' }));
  34. st.ok(isDescriptor({ writable: true }));
  35. st.end();
  36. });
  37. t.test('should be false when the value is not a valid descriptor', function (st) {
  38. st.notOk(isDescriptor('foo'));
  39. st.notOk(isDescriptor({}));
  40. st.notOk(isDescriptor({ configurable: true }));
  41. st.notOk(isDescriptor({ enumerable: true }));
  42. st.notOk(isDescriptor({
  43. get: undefined,
  44. set: undefined,
  45. enumerable: true,
  46. configurable: true,
  47. }));
  48. st.end();
  49. });
  50. t.end();
  51. });