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.

53 lines
1.5 KiB

4 years ago
  1. var inspect = require('../');
  2. var test = require('tape');
  3. test('element', function (t) {
  4. t.plan(3);
  5. var elem = {
  6. nodeName: 'div',
  7. attributes: [{ name: 'class', value: 'row' }],
  8. getAttribute: function (key) { return key; },
  9. childNodes: []
  10. };
  11. var obj = [1, elem, 3];
  12. t.deepEqual(inspect(obj), '[ 1, <div class="row"></div>, 3 ]');
  13. t.deepEqual(inspect(obj, { quoteStyle: 'single' }), "[ 1, <div class='row'></div>, 3 ]");
  14. t.deepEqual(inspect(obj, { quoteStyle: 'double' }), '[ 1, <div class="row"></div>, 3 ]');
  15. });
  16. test('element no attr', function (t) {
  17. t.plan(1);
  18. var elem = {
  19. nodeName: 'div',
  20. getAttribute: function (key) { return key; },
  21. childNodes: []
  22. };
  23. var obj = [1, elem, 3];
  24. t.deepEqual(inspect(obj), '[ 1, <div></div>, 3 ]');
  25. });
  26. test('element with contents', function (t) {
  27. t.plan(1);
  28. var elem = {
  29. nodeName: 'div',
  30. getAttribute: function (key) { return key; },
  31. childNodes: [{ nodeName: 'b' }]
  32. };
  33. var obj = [1, elem, 3];
  34. t.deepEqual(inspect(obj), '[ 1, <div>...</div>, 3 ]');
  35. });
  36. test('element instance', function (t) {
  37. t.plan(1);
  38. var h = global.HTMLElement;
  39. global.HTMLElement = function (name, attr) {
  40. this.nodeName = name;
  41. this.attributes = attr;
  42. };
  43. global.HTMLElement.prototype.getAttribute = function () {};
  44. var elem = new global.HTMLElement('div', []);
  45. var obj = [1, elem, 3];
  46. t.deepEqual(inspect(obj), '[ 1, <div></div>, 3 ]');
  47. global.HTMLElement = h;
  48. });