append.spec.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { compile } from '../../../packages/weex-template-compiler'
  2. import { strToRegExp } from '../helpers/index'
  3. describe('append props', () => {
  4. it('add append="tree" on <cell>', () => {
  5. const { render, staticRenderFns, errors } = compile(`<list><cell></cell></list>`)
  6. expect(render).not.toBeUndefined()
  7. expect(staticRenderFns).not.toBeUndefined()
  8. expect(staticRenderFns.length).toEqual(1)
  9. expect(staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`))
  10. expect(staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`))
  11. expect(errors).toEqual([])
  12. })
  13. it('override append="node" on <cell>', () => {
  14. const { render, staticRenderFns, errors } = compile(`<list><cell append="node"></cell></list>`)
  15. expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"node"}`))
  16. expect(errors).toEqual([])
  17. })
  18. it('add append="tree" on <header>', () => {
  19. const { render, staticRenderFns, errors } = compile(`<list><header></header></list>`)
  20. expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`))
  21. expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`))
  22. expect(errors).toEqual([])
  23. })
  24. it('add append="tree" on <recycle-list>', () => {
  25. const { render, staticRenderFns, errors } = compile(`<recycle-list for="item in list"><div></div></recycle-list>`)
  26. expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`))
  27. expect(render + staticRenderFns).toMatch(strToRegExp(`"append":"tree"`))
  28. expect(errors).toEqual([])
  29. })
  30. it('add append="tree" on <cell-slot>', () => {
  31. const { render, staticRenderFns, errors } = compile(`<list><cell-slot></cell-slot></list>`)
  32. expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`))
  33. expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`))
  34. expect(errors).toEqual([])
  35. })
  36. it('override append="node" on <cell-slot>', () => {
  37. const { render, staticRenderFns, errors } = compile(`<list><cell-slot append="node"></cell-slot></list>`)
  38. expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"node"}`))
  39. expect(errors).toEqual([])
  40. })
  41. })