Skip to content

Commit 9381736

Browse files
kellymeddyerburgh
authored andcommitted
fix: allow plugins to be re-installed in localVue instance (fixes #406) (#411)
1 parent 91472e4 commit 9381736

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/create-local-vue.js

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ function createLocalVue (): Component {
3232
instance.options._base = instance
3333

3434
// compat for vue-router < 2.7.1 where it does not allow multiple installs
35+
if (instance._installedPlugins && instance._installedPlugins.length) {
36+
instance._installedPlugins.length = 0
37+
}
3538
const use = instance.use
3639
instance.use = (plugin, ...rest) => {
3740
if (plugin.installed === true) {

test/specs/create-local-vue.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createLocalVue } from '~vue-test-utils'
2+
import Vue from 'vue'
23
import Vuex from 'vuex'
34
import Vuetify from 'vuetify'
45
import VueRouter from 'vue-router'
@@ -113,6 +114,27 @@ describe('createLocalVue', () => {
113114
localVue.use(Vuetify)
114115
})
115116

117+
it('installs plugin into local Vue regardless of previous install in Vue', () => {
118+
let installCount = 0
119+
120+
class Plugin {}
121+
Plugin.install = function (_Vue) {
122+
if (_Vue._installedPlugins) {
123+
expect(_Vue._installedPlugins.indexOf(Plugin)).to.equal(-1)
124+
}
125+
installCount++
126+
}
127+
128+
Vue.use(Plugin)
129+
const localVue = createLocalVue()
130+
localVue.use(Plugin)
131+
132+
if (localVue._installedPlugins) {
133+
expect(localVue._installedPlugins.indexOf(Plugin)).to.equal(0)
134+
}
135+
expect(installCount).to.equal(2)
136+
})
137+
116138
it('has an errorHandler', () => {
117139
const localVue = createLocalVue()
118140

0 commit comments

Comments
 (0)