v-model.spec.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { compile } from '../../../packages/weex-template-compiler'
  2. import { strToRegExp } from '../helpers/index'
  3. describe('compile v-model', () => {
  4. it('should compile modelable native component', () => {
  5. const { render, staticRenderFns, errors } = compile(`<div><input v-model="x" /></div>`)
  6. expect(render).not.toBeUndefined()
  7. expect(render).toMatch(strToRegExp(`attrs:{"value":(x)}`))
  8. expect(render).toMatch(strToRegExp(`on:{"input":function($event){x=$event.target.attr.value}}`))
  9. expect(staticRenderFns).toEqual([])
  10. expect(errors).toEqual([])
  11. })
  12. it('should compile other component with whole $event as the value', () => {
  13. const { render, staticRenderFns, errors } = compile(`<div><foo v-model="x" /></div>`)
  14. expect(render).not.toBeUndefined()
  15. expect(render).toMatch(strToRegExp(`attrs:{"value":(x)}`))
  16. expect(render).toMatch(strToRegExp(`on:{"input":function($event){x=$event}}`))
  17. expect(staticRenderFns).toEqual([])
  18. expect(errors).toEqual([])
  19. })
  20. it('should compile with lazy modifier', () => {
  21. const { render, staticRenderFns, errors } = compile(`<div><foo v-model.lazy="x" /></div>`)
  22. expect(render).not.toBeUndefined()
  23. expect(render).toMatch(strToRegExp(`attrs:{"value":(x)}`))
  24. expect(render).toMatch(strToRegExp(`on:{"change":function($event){x=$event}}`))
  25. expect(staticRenderFns).toEqual([])
  26. expect(errors).toEqual([])
  27. })
  28. it('should compile with trim modifier for modelable native component', () => {
  29. const { render, staticRenderFns, errors } = compile(`<div><input v-model.trim="x" /><foo v-model.trim="y" /></div>`)
  30. expect(render).not.toBeUndefined()
  31. expect(render).toMatch(strToRegExp(`attrs:{"value":(x)}`))
  32. expect(render).toMatch(strToRegExp(`attrs:{"value":(y)}`))
  33. expect(render).toMatch(strToRegExp(`on:{"input":function($event){x=$event.target.attr.value.trim()}}`))
  34. expect(render).toMatch(strToRegExp(`on:{"input":function($event){y=$event}}`))
  35. expect(staticRenderFns).toEqual([])
  36. expect(errors).toEqual([])
  37. })
  38. it('should compile with trim & lazy modifier', () => {
  39. const { render, staticRenderFns, errors } = compile(`<div><input v-model.trim.lazy="x" /><input v-model.lazy.trim="y" /></div>`)
  40. expect(render).not.toBeUndefined()
  41. expect(render).toMatch(strToRegExp(`attrs:{"value":(x)}`))
  42. expect(render).toMatch(strToRegExp(`attrs:{"value":(y)}`))
  43. expect(render).toMatch(strToRegExp(`on:{"change":function($event){x=$event.target.attr.value.trim()}}`))
  44. expect(render).toMatch(strToRegExp(`on:{"change":function($event){y=$event.target.attr.value.trim()}}`))
  45. expect(staticRenderFns).toEqual([])
  46. expect(errors).toEqual([])
  47. })
  48. })