render.spec.ts 1.2 KB

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