Skip to content

Commit

Permalink
fix(setup): Vue.extend(Comp).extend({}) - vue-test-utils (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
pikax committed Jun 16, 2020
1 parent 66f58ba commit ce932bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/install.ts
Expand Up @@ -9,6 +9,8 @@ import { VueConstructor } from 'vue'
*/
function mergeData(from: AnyObject, to: AnyObject): Object {
if (!from) return to
if (!to) return from

let key: any
let toVal: any
let fromVal: any
Expand Down Expand Up @@ -56,8 +58,8 @@ export function install(
) {
return function mergedSetupFn(props: any, context: any) {
return mergeData(
typeof parent === 'function' ? parent(props, context) || {} : {},
typeof child === 'function' ? child(props, context) || {} : {}
typeof parent === 'function' ? parent(props, context) || {} : undefined,
typeof child === 'function' ? child(props, context) || {} : undefined
)
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/setup.spec.js
Expand Up @@ -719,4 +719,16 @@ describe('setup', () => {
expect(context).toBe(vm)
})
})

it('should work after extending with an undefined setup', () => {
const opts = {
setup() {
return () => h('div', 'Composition-api')
},
}
const Constructor = Vue.extend(opts).extend({})

const vm = new Vue(Constructor).$mount()
expect(vm.$el.textContent).toBe('Composition-api')
})
})

0 comments on commit ce932bf

Please sign in to comment.