Parcourir la source

test: test for mixin/extends props merging

Evan You il y a 6 ans
Parent
commit
215c106297
1 fichiers modifiés avec 44 ajouts et 1 suppressions
  1. 44 1
      packages/runtime-core/__tests__/componentProps.spec.ts

+ 44 - 1
packages/runtime-core/__tests__/componentProps.spec.ts

@@ -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)
+  })
 })