Przeglądaj źródła

add options render tests (#2966)

ref: #2872
kazuya kawaguchi 10 lat temu
rodzic
commit
f5bc3e584f
1 zmienionych plików z 30 dodań i 0 usunięć
  1. 30 0
      test/unit/features/options/render.spec.js

+ 30 - 0
test/unit/features/options/render.spec.js

@@ -0,0 +1,30 @@
+import Vue from 'entries/web-runtime'
+
+describe('Options render', () => {
+  it('basic usage', () => {
+    const vm = new Vue({
+      render () {
+        const h = this.$createElement
+        const children = []
+        for (let i = 0; i < this.items.length; i++) {
+          children.push(h('li', { staticClass: 'task' }, [this.items[i].name]))
+        }
+        return h('ul', { staticClass: 'tasks' }, children)
+      },
+      data: {
+        items: [{ id: 1, name: 'task1' }, { id: 2, name: 'task2' }]
+      }
+    }).$mount()
+    expect(vm.$el.tagName).toBe('UL')
+    for (let i = 0; i < vm.$el.children.length; i++) {
+      const li = vm.$el.children[i]
+      expect(li.tagName).toBe('LI')
+      expect(li.textContent).toBe(vm.items[i].name)
+    }
+  })
+
+  it('should warn non `render` option and non `template` option', () => {
+    new Vue().$mount()
+    expect('Failed to mount component: template or render function not defined.').toHaveBeenWarned()
+  })
+})