Skip to content

fix: allow plugins to be re-installed in localVue instance (fixes #406) #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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