Skip to content

fix: options from the extended component are not inherited #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {

export default function wrap (Vue, Component) {
const isAsync = typeof Component === 'function' && !Component.cid

if (!isAsync && Component.extends && Vue.util.mergeOptions) {
Component = Vue.util.mergeOptions(Component, Component.extends)
}
let isInitialized = false
let hyphenatedPropsList
let camelizedPropsList
Expand Down
26 changes: 26 additions & 0 deletions test/fixtures/extended-component-properties.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script src="../../node_modules/vue/dist/vue.js"></script>
<script type="module">
import wrap from '../../src/index.js'

const component = {
template: `<div>{{ foo }} {{ someProp }}</div>`,
props: {
foo: {
type: Number,
default: 123
},
'some-prop': {
type: String,
default: 'bar'
}
}
}

customElements.define('my-element', wrap(Vue, {
extends: component,
}))

window.el = document.querySelector('my-element')
</script>

<my-element></my-element>
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ test('properties', async () => {
expect(newBar).toBe('lol')
})

test('extended-component-properties', async () => {
const { page } = await launchPage(`extended-component-properties`)

// props proxying: get
const foo = await page.evaluate(() => el.foo)
expect(foo).toBe(123)

// get camelCase
const someProp = await page.evaluate(() => el.someProp)
expect(someProp).toBe('bar')

// props proxying: set
await page.evaluate(() => {
el.foo = 234
el.someProp = 'lol'
})
const newFoo = await page.evaluate(() => el.vueComponent.foo)

expect(newFoo).toBe(234)
const newBar = await page.evaluate(() => el.vueComponent.someProp)
expect(newBar).toBe('lol')
})

test('attributes', async () => {
const { page } = await launchPage(`attributes`)

Expand Down