diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index 669249157..336c5c197 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -123,7 +123,13 @@ export default function createInstance( createChildren(this, h, options) ) } - const Parent = _Vue.extend(parentComponentOptions) + + // options "propsData" can only be used during instance creation with the `new` keyword + const { propsData, ...rest } = options // eslint-disable-line + const Parent = _Vue.extend({ + ...rest, + ...parentComponentOptions + }) return new Parent() } diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index e5f3b7873..8cb454ccb 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -419,6 +419,24 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => { expect(wrapper.html()).toEqual('
composition api
') }) + it('allows accessing $root with composition api plugin', () => { + const localVue = createLocalVue() + localVue.use(Vuex) + localVue.use(CompositionAPI) + const store = new Vuex.Store({ + state: { + msg: 'msg' + } + }) + const Comp = { + setup(props, ctx) { + return () => createElement('div', ctx.root.$store.state.msg) + } + } + const wrapper = mount(Comp, { localVue, store }) + expect(wrapper.html()).toEqual('
msg
') + }) + itDoNotRunIf.skip( vueVersion >= 2.5, 'throws if component throws during update',