From fc88c25c25f39bf5dc226e23f2d32b5afc3fac7b Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 5 Feb 2018 10:16:17 -0600 Subject: [PATCH 1/2] fix: allow plugins to be re-installed in localVue instance closes #406 --- src/create-local-vue.js | 1 + test/specs/create-local-vue.spec.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/create-local-vue.js b/src/create-local-vue.js index 2eb2ba730..d9733adad 100644 --- a/src/create-local-vue.js +++ b/src/create-local-vue.js @@ -32,6 +32,7 @@ function createLocalVue (): Component { instance.options._base = instance // compat for vue-router < 2.7.1 where it does not allow multiple installs + instance._installedPlugins = [] 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..6ef72a336 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,23 @@ 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) { + expect(_Vue._installedPlugins.indexOf(Plugin)).to.equal(-1) + installCount++ + } + + Vue.use(Plugin) + const localVue = createLocalVue() + localVue.use(Plugin) + + expect(localVue._installedPlugins.indexOf(Plugin)).to.equal(0) + expect(installCount).to.equal(2) + }) + it('has an errorHandler', () => { const localVue = createLocalVue() From 421109b18a75bfda3ea87aeb0c7ba8a2715f3cdb Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 5 Feb 2018 13:20:53 -0600 Subject: [PATCH 2/2] Add support for Vue 2.0.x --- src/create-local-vue.js | 4 +++- test/specs/create-local-vue.spec.js | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/create-local-vue.js b/src/create-local-vue.js index d9733adad..df69c590e 100644 --- a/src/create-local-vue.js +++ b/src/create-local-vue.js @@ -32,7 +32,9 @@ function createLocalVue (): Component { instance.options._base = instance // compat for vue-router < 2.7.1 where it does not allow multiple installs - instance._installedPlugins = [] + 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 6ef72a336..a9a822839 100644 --- a/test/specs/create-local-vue.spec.js +++ b/test/specs/create-local-vue.spec.js @@ -119,7 +119,9 @@ describe('createLocalVue', () => { class Plugin {} Plugin.install = function (_Vue) { - expect(_Vue._installedPlugins.indexOf(Plugin)).to.equal(-1) + if (_Vue._installedPlugins) { + expect(_Vue._installedPlugins.indexOf(Plugin)).to.equal(-1) + } installCount++ } @@ -127,7 +129,9 @@ describe('createLocalVue', () => { const localVue = createLocalVue() localVue.use(Plugin) - expect(localVue._installedPlugins.indexOf(Plugin)).to.equal(0) + if (localVue._installedPlugins) { + expect(localVue._installedPlugins.indexOf(Plugin)).to.equal(0) + } expect(installCount).to.equal(2) })