diff --git a/src/create-local-vue.js b/src/create-local-vue.js index 2eb2ba730..df69c590e 100644 --- a/src/create-local-vue.js +++ b/src/create-local-vue.js @@ -32,6 +32,9 @@ function createLocalVue (): Component { instance.options._base = instance // compat for vue-router < 2.7.1 where it does not allow multiple installs + if (instance._installedPlugins && instance._installedPlugins.length) { + instance._installedPlugins.length = 0 + } const use = instance.use instance.use = (plugin, ...rest) => { if (plugin.installed === true) { diff --git a/test/specs/create-local-vue.spec.js b/test/specs/create-local-vue.spec.js index c9aa8e92b..a9a822839 100644 --- a/test/specs/create-local-vue.spec.js +++ b/test/specs/create-local-vue.spec.js @@ -1,4 +1,5 @@ import { createLocalVue } from '~vue-test-utils' +import Vue from 'vue' import Vuex from 'vuex' import Vuetify from 'vuetify' import VueRouter from 'vue-router' @@ -113,6 +114,27 @@ describe('createLocalVue', () => { localVue.use(Vuetify) }) + it('installs plugin into local Vue regardless of previous install in Vue', () => { + let installCount = 0 + + class Plugin {} + Plugin.install = function (_Vue) { + if (_Vue._installedPlugins) { + expect(_Vue._installedPlugins.indexOf(Plugin)).to.equal(-1) + } + installCount++ + } + + Vue.use(Plugin) + const localVue = createLocalVue() + localVue.use(Plugin) + + if (localVue._installedPlugins) { + expect(localVue._installedPlugins.indexOf(Plugin)).to.equal(0) + } + expect(installCount).to.equal(2) + }) + it('has an errorHandler', () => { const localVue = createLocalVue()