2
0

render.spec.js 1.1 KB

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