saneObjectToDom.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Generated by CoffeeScript 1.6.3
  2. var s2d;
  3. require('./_prepare');
  4. s2d = mod('saneObjectToDom');
  5. describe("_arrayToChildren()");
  6. it("should work", function() {
  7. var a, aChild, b, bChildren, node, ret, _i, _len;
  8. ret = s2d._arrayToChildren([
  9. {
  10. a: 'text'
  11. }, {
  12. 'b.someClass': ['b1', 'b2']
  13. }, {
  14. c: [
  15. {
  16. d: 'text'
  17. }, {
  18. e: []
  19. }
  20. ]
  21. }
  22. ]);
  23. ret.should.be.an('array');
  24. ret.should.have.length.of(3);
  25. for (_i = 0, _len = ret.length; _i < _len; _i++) {
  26. node = ret[_i];
  27. node.should.be.an('object');
  28. node.should.have.keys(['type', 'name', 'attribs', 'children', 'next', 'prev', 'parent']);
  29. }
  30. a = ret[0];
  31. a.children.should.be.an('array');
  32. a.children.should.have.length.of(1);
  33. aChild = a.children[0];
  34. aChild.should.be.an('object');
  35. aChild.should.be.like({
  36. type: 'text',
  37. data: 'text'
  38. });
  39. expect(a.prev).to.equal(null);
  40. expect(a.parent).to.equal(null);
  41. b = ret[1];
  42. a.next.should.equal(b);
  43. b.prev.should.equal(a);
  44. b.attribs.should.be.like({
  45. "class": 'someClass'
  46. });
  47. bChildren = b.children;
  48. bChildren[0].should.be.like({
  49. type: 'text',
  50. data: 'b1'
  51. });
  52. bChildren[1].should.be.like({
  53. type: 'text',
  54. data: 'b2'
  55. });
  56. return ret.should.have.deep.property('[2].children[1].name', 'e');
  57. });
  58. describe("_parseTag");
  59. it("should work", function() {
  60. return s2d._parseTag('tagName#id.c1.c2[a=b, d="1 2 3"]').should.be.like({
  61. name: 'tagName',
  62. attribs: {
  63. id: 'id',
  64. "class": 'c1 c2'
  65. }
  66. });
  67. });