saneObjectToDom.coffee 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. require './_prepare'
  2. s2d = mod 'saneObjectToDom'
  3. describe "_arrayToChildren()"
  4. it "should work", ->
  5. ret = s2d._arrayToChildren [
  6. {
  7. a: 'text'
  8. }
  9. {
  10. 'b.someClass': ['b1', 'b2']
  11. }
  12. {
  13. c: [
  14. {d: 'text'}
  15. {e: []}
  16. ]
  17. }
  18. ]
  19. ret.should.be.an 'array'
  20. ret.should.have.length.of 3
  21. for node in ret
  22. node.should.be.an 'object'
  23. node.should.have
  24. .keys ['type', 'name', 'attribs', 'children', 'next', 'prev', 'parent']
  25. a = ret[0]
  26. a.children.should.be.an 'array'
  27. a.children.should.have.length.of 1
  28. aChild = a.children[0]
  29. aChild.should.be.an 'object'
  30. aChild.should.be.like {type: 'text', data: 'text'}
  31. expect(a.prev).to.equal null
  32. expect(a.parent).to.equal null
  33. b = ret[1]
  34. a.next.should.equal b
  35. b.prev.should.equal a
  36. b.attribs.should.be.like
  37. class: 'someClass'
  38. bChildren = b.children
  39. bChildren[0].should.be.like {type: 'text', data: 'b1'}
  40. bChildren[1].should.be.like {type: 'text', data: 'b2'}
  41. ret.should.have.deep.property '[2].children[1].name', 'e'
  42. describe "_parseTag"
  43. it "should work", ->
  44. s2d.
  45. _parseTag('tagName#id.c1.c2[a=b, d="1 2 3"]')
  46. .should.be.like
  47. name: 'tagName'
  48. attribs:
  49. id: 'id'
  50. class: 'c1 c2'