]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(runtime-core): add test for rendererComponent (#1393)
author春去春又来 <cui_xiaorui@126.com>
Wed, 15 Jul 2020 13:34:23 +0000 (21:34 +0800)
committerGitHub <noreply@github.com>
Wed, 15 Jul 2020 13:34:23 +0000 (09:34 -0400)
packages/runtime-core/__tests__/rendererComponent.spec.ts

index e5d2dd2e63c3418665671d1f8f4b3086c2d7b7c8..101605be8ed518b4955b06201d008fb5cb47afef 100644 (file)
@@ -40,4 +40,45 @@ describe('renderer: component', () => {
     expect(serializeInner(root)).toBe(`<span></span>`)
     expect(parentVnode!.el).toBe(childVnode2!.el)
   })
+
+  it('should create an Component with props', () => {
+    const Comp = {
+      render: () => {
+        return h('div')
+      }
+    }
+    const root = nodeOps.createElement('div')
+    render(h(Comp, { id: 'foo', class: 'bar' }), root)
+    expect(serializeInner(root)).toBe(`<div id="foo" class="bar"></div>`)
+  })
+
+  it('should create an Component with direct text children', () => {
+    const Comp = {
+      render: () => {
+        return h('div', 'test')
+      }
+    }
+    const root = nodeOps.createElement('div')
+    render(h(Comp, { id: 'foo', class: 'bar' }), root)
+    expect(serializeInner(root)).toBe(`<div id="foo" class="bar">test</div>`)
+  })
+
+  it('should update an Component tag which is already mounted', () => {
+    const Comp1 = {
+      render: () => {
+        return h('div', 'foo')
+      }
+    }
+    const root = nodeOps.createElement('div')
+    render(h(Comp1), root)
+    expect(serializeInner(root)).toBe('<div>foo</div>')
+
+    const Comp2 = {
+      render: () => {
+        return h('span', 'foo')
+      }
+    }
+    render(h(Comp2), root)
+    expect(serializeInner(root)).toBe('<span>foo</span>')
+  })
 })