render.spec.js 986 B

123456789101112131415161718192021222324252627282930
  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 /* string as children*/))
  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('should warn non `render` option and non `template` option', () => {
  25. new Vue().$mount()
  26. expect('Failed to mount component: template or render function not defined.').toHaveBeenWarned()
  27. })
  28. })