Skip to content

Commit

Permalink
fix: allow plugins to be re-installed in localVue instance (fixes #406)…
Browse files Browse the repository at this point in the history
… (#411)
  • Loading branch information
kellym authored and eddyerburgh committed Feb 5, 2018
1 parent 91472e4 commit 9381736
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/create-local-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions test/specs/create-local-vue.spec.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 9381736

Please sign in to comment.