index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.notOk(isDescriptor([]), 'Array is not a descriptor');
  10. st.end();
  11. });
  12. t.test('is false when the object has data descriptor properties:', function (st) {
  13. st.notOk(isDescriptor({ get: noop, writable: true }));
  14. st.notOk(isDescriptor({ get: noop, value: true }));
  15. st.end();
  16. });
  17. t.test('is not false when unrecognized properties are defined:', function (st) {
  18. st.ok(isDescriptor({ get: noop, foo: true }));
  19. st.ok(isDescriptor({ get: noop, bar: true }));
  20. st.end();
  21. });
  22. t.test('is false when a get or set are not functions:', function (st) {
  23. st.notOk(isDescriptor({ get: noop, set: 'baz' }));
  24. st.notOk(isDescriptor({ get: 'foo', set: noop }));
  25. st.notOk(isDescriptor({ get: 'foo', bar: 'baz' }));
  26. st.notOk(isDescriptor({ get: 'foo', set: 'baz' }));
  27. st.notOk(isDescriptor({ get: 'foo' }));
  28. st.end();
  29. });
  30. t.test('is true when "get" is not defined:', function (st) {
  31. st.ok(isDescriptor({ set: noop }));
  32. st.end();
  33. });
  34. t.test('is true when the object has valid properties:', function (st) {
  35. st.ok(isDescriptor({ get: noop, set: noop }));
  36. st.ok(isDescriptor({ get: noop }));
  37. st.end();
  38. });
  39. t.test('is false when a value is not the correct type:', function (st) {
  40. st.notOk(isDescriptor({ get: noop, set: noop, enumerable: 'foo' }));
  41. st.notOk(isDescriptor({ set: noop, configurable: 'foo' }));
  42. st.notOk(isDescriptor({ get: noop, configurable: 'foo' }));
  43. st.end();
  44. });
  45. t.end();
  46. });