Skip to content

Commit

Permalink
fix(vue-test): prevent warning when using multiple localVue (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
pikax committed Sep 18, 2020
1 parent d2df842 commit 5484bb7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/runtimeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export function getRegisteredVueOrDefault(): VueConstructor {
}

export function setVueConstructor(Vue: VueConstructor) {
if (__DEV__ && vueConstructor) {
// @ts-ignore
if (__DEV__ && vueConstructor && Vue.__proto__ !== vueConstructor.__proto__) {
warn('Another instance of vue installed')
}
vueConstructor = Vue
Expand Down
24 changes: 21 additions & 3 deletions test/use.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Vue from 'vue'
import CompositionApi from '../src'
import { createLocalVue } from './helpers/create-local-vue'
import { mockWarn } from './helpers'
Expand All @@ -12,7 +13,26 @@ describe('use', () => {
const localVueTwo = createLocalVue()
localVueTwo.use(CompositionApi)

expect('Another instance of vue installed').toHaveBeenWarned()
expect('Another instance of vue installed').not.toHaveBeenWarned()
})

it('should warn install in multiple vue', () => {
try {
const fakeVue = {
version: '2._.x',
config: {
optionMergeStrategies: {},
},
mixin: jest.fn(),
}

// @ts-ignore
CompositionApi.install(fakeVue)
expect('Another instance of vue installed').toHaveBeenWarned()
} finally {
Vue.use(CompositionApi)
expect('Another instance of vue installed').toHaveBeenWarned()
}
})

it('should warn installing multiple times', () => {
Expand All @@ -29,7 +49,5 @@ describe('use', () => {
}).toThrowError(
'already installed. Vue.use(VueCompositionAPI) should be called only once.'
)

expect('Another instance of vue installed').toHaveBeenWarned()
})
})

0 comments on commit 5484bb7

Please sign in to comment.