b6baa80a1d3490a99611c0329f99de803f44b4317a172e271cc9f81c882132add2e294f48392ce62f6de90a5d91f3c2654c34cf4523facf2969f3dfdd91cbf 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. var is = require('../src/is');
  2. describe('is', function() {
  3. before(function() {
  4. global.node = document.createElement('div');
  5. global.node.setAttribute('id', 'foo');
  6. global.node.setAttribute('class', 'foo');
  7. document.body.appendChild(global.node);
  8. });
  9. after(function() {
  10. document.body.innerHTML = '';
  11. });
  12. describe('is.node', function() {
  13. it('should be considered as node', function() {
  14. assert.ok(is.node(document.getElementById('foo')));
  15. assert.ok(is.node(document.getElementsByTagName('div')[0]));
  16. assert.ok(is.node(document.getElementsByClassName('foo')[0]));
  17. assert.ok(is.node(document.querySelector('.foo')));
  18. });
  19. it('should not be considered as node', function() {
  20. assert.notOk(is.node(undefined));
  21. assert.notOk(is.node(null));
  22. assert.notOk(is.node(false));
  23. assert.notOk(is.node(true));
  24. assert.notOk(is.node(function () {}));
  25. assert.notOk(is.node([]));
  26. assert.notOk(is.node({}));
  27. assert.notOk(is.node(/a/g));
  28. assert.notOk(is.node(new RegExp('a', 'g')));
  29. assert.notOk(is.node(new Date()));
  30. assert.notOk(is.node(42));
  31. assert.notOk(is.node(NaN));
  32. assert.notOk(is.node(Infinity));
  33. assert.notOk(is.node(new Number(42)));
  34. });
  35. });
  36. describe('is.nodeList', function() {
  37. it('should be considered as nodeList', function() {
  38. assert.ok(is.nodeList(document.getElementsByTagName('div')));
  39. assert.ok(is.nodeList(document.getElementsByClassName('foo')));
  40. assert.ok(is.nodeList(document.querySelectorAll('.foo')));
  41. });
  42. it('should not be considered as nodeList', function() {
  43. assert.notOk(is.nodeList(undefined));
  44. assert.notOk(is.nodeList(null));
  45. assert.notOk(is.nodeList(false));
  46. assert.notOk(is.nodeList(true));
  47. assert.notOk(is.nodeList(function () {}));
  48. assert.notOk(is.nodeList([]));
  49. assert.notOk(is.nodeList({}));
  50. assert.notOk(is.nodeList(/a/g));
  51. assert.notOk(is.nodeList(new RegExp('a', 'g')));
  52. assert.notOk(is.nodeList(new Date()));
  53. assert.notOk(is.nodeList(42));
  54. assert.notOk(is.nodeList(NaN));
  55. assert.notOk(is.nodeList(Infinity));
  56. assert.notOk(is.nodeList(new Number(42)));
  57. });
  58. });
  59. describe('is.string', function() {
  60. it('should be considered as string', function() {
  61. assert.ok(is.string('abc'));
  62. assert.ok(is.string(new String('abc')));
  63. });
  64. it('should not be considered as string', function() {
  65. assert.notOk(is.string(undefined));
  66. assert.notOk(is.string(null));
  67. assert.notOk(is.string(false));
  68. assert.notOk(is.string(true));
  69. assert.notOk(is.string(function () {}));
  70. assert.notOk(is.string([]));
  71. assert.notOk(is.string({}));
  72. assert.notOk(is.string(/a/g));
  73. assert.notOk(is.string(new RegExp('a', 'g')));
  74. assert.notOk(is.string(new Date()));
  75. assert.notOk(is.string(42));
  76. assert.notOk(is.string(NaN));
  77. assert.notOk(is.string(Infinity));
  78. assert.notOk(is.string(new Number(42)));
  79. });
  80. });
  81. describe('is.fn', function() {
  82. it('should be considered as function', function() {
  83. assert.ok(is.fn(function () {}));
  84. });
  85. it('should not be considered as function', function() {
  86. assert.notOk(is.fn(undefined));
  87. assert.notOk(is.fn(null));
  88. assert.notOk(is.fn(false));
  89. assert.notOk(is.fn(true));
  90. assert.notOk(is.fn([]));
  91. assert.notOk(is.fn({}));
  92. assert.notOk(is.fn(/a/g));
  93. assert.notOk(is.fn(new RegExp('a', 'g')));
  94. assert.notOk(is.fn(new Date()));
  95. assert.notOk(is.fn(42));
  96. assert.notOk(is.fn(NaN));
  97. assert.notOk(is.fn(Infinity));
  98. assert.notOk(is.fn(new Number(42)));
  99. });
  100. });
  101. });