]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: test for mixin/extends props merging
authorEvan You <yyx990803@gmail.com>
Tue, 9 Jun 2020 20:20:33 +0000 (16:20 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 9 Jun 2020 20:20:33 +0000 (16:20 -0400)
packages/runtime-core/__tests__/componentProps.spec.ts

index 26549cb1eff138f73cc4ec09921b8c22ec8f770a..59167ea53513b8bd6df391539053575b912e86f4 100644 (file)
@@ -6,7 +6,8 @@ import {
   nodeOps,
   FunctionalComponent,
   defineComponent,
-  ref
+  ref,
+  serializeInner
 } from '@vue/runtime-test'
 import { render as domRender, nextTick } from 'vue'
 import { mockWarn } from '@vue/shared'
@@ -259,4 +260,46 @@ describe('component props', () => {
     }).toThrow(TypeError)
     expect(`Attempting to mutate prop "foo"`).toHaveBeenWarned()
   })
+
+  test('merging props from mixins and extends', () => {
+    let setupProps: any
+    let renderProxy: any
+
+    const E = {
+      props: ['base']
+    }
+    const M1 = {
+      props: ['m1']
+    }
+    const M2 = {
+      props: { m2: null }
+    }
+    const Comp = {
+      props: ['self'],
+      mixins: [M1, M2],
+      extends: E,
+      setup(props: any) {
+        setupProps = props
+      },
+      render(this: any) {
+        renderProxy = this
+        return h('div', [this.self, this.base, this.m1, this.m2])
+      }
+    }
+
+    const root = nodeOps.createElement('div')
+    const props = {
+      self: 'from self, ',
+      base: 'from base, ',
+      m1: 'from mixin 1, ',
+      m2: 'from mixin 2'
+    }
+    render(h(Comp, props), root)
+
+    expect(serializeInner(root)).toMatch(
+      `from self, from base, from mixin 1, from mixin 2`
+    )
+    expect(setupProps).toMatchObject(props)
+    expect(renderProxy.$props).toMatchObject(props)
+  })
 })