render.spec.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import Vue from 'entries/web-runtime'
  2. describe('Options render', () => {
  3. it('basic usage', () => {
  4. const vm = new Vue({
  5. render () {
  6. const h = this.$createElement
  7. const children = []
  8. for (let i = 0; i < this.items.length; i++) {
  9. children.push(h('li', { staticClass: 'task' }, [this.items[i].name]))
  10. }
  11. return h('ul', { staticClass: 'tasks' }, children)
  12. },
  13. data: {
  14. items: [{ id: 1, name: 'task1' }, { id: 2, name: 'task2' }]
  15. }
  16. }).$mount()
  17. expect(vm.$el.tagName).toBe('UL')
  18. for (let i = 0; i < vm.$el.children.length; i++) {
  19. const li = vm.$el.children[i]
  20. expect(li.tagName).toBe('LI')
  21. expect(li.textContent).toBe(vm.items[i].name)
  22. }
  23. })
  24. it('allow null data', () => {
  25. const vm = new Vue({
  26. render () {
  27. const h = this.$createElement
  28. return h('div', null, 'hello' /* string as children*/)
  29. }
  30. }).$mount()
  31. expect(vm.$el.tagName).toBe('DIV')
  32. expect(vm.$el.textContent).toBe('hello')
  33. })
  34. it('should warn non `render` option and non `template` option', () => {
  35. new Vue().$mount()
  36. expect('Failed to mount component: template or render function not defined.').toHaveBeenWarned()
  37. })
  38. })