Skip to content

Commit fc88c25

Browse files
committed
fix: allow plugins to be re-installed in localVue instance
closes #406
1 parent 91472e4 commit fc88c25

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/create-local-vue.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ 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+
instance._installedPlugins = []
3536
const use = instance.use
3637
instance.use = (plugin, ...rest) => {
3738
if (plugin.installed === true) {

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

+18
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,23 @@ 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+
expect(_Vue._installedPlugins.indexOf(Plugin)).to.equal(-1)
123+
installCount++
124+
}
125+
126+
Vue.use(Plugin)
127+
const localVue = createLocalVue()
128+
localVue.use(Plugin)
129+
130+
expect(localVue._installedPlugins.indexOf(Plugin)).to.equal(0)
131+
expect(installCount).to.equal(2)
132+
})
133+
116134
it('has an errorHandler', () => {
117135
const localVue = createLocalVue()
118136

0 commit comments

Comments
 (0)