Skip to content

Commit 5484bb7

Browse files
authored
fix(vue-test): prevent warning when using multiple localVue (vuejs#531)
1 parent d2df842 commit 5484bb7

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/runtimeContext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export function getRegisteredVueOrDefault(): VueConstructor {
4646
}
4747

4848
export function setVueConstructor(Vue: VueConstructor) {
49-
if (__DEV__ && vueConstructor) {
49+
// @ts-ignore
50+
if (__DEV__ && vueConstructor && Vue.__proto__ !== vueConstructor.__proto__) {
5051
warn('Another instance of vue installed')
5152
}
5253
vueConstructor = Vue

test/use.spec.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Vue from 'vue'
12
import CompositionApi from '../src'
23
import { createLocalVue } from './helpers/create-local-vue'
34
import { mockWarn } from './helpers'
@@ -12,7 +13,26 @@ describe('use', () => {
1213
const localVueTwo = createLocalVue()
1314
localVueTwo.use(CompositionApi)
1415

15-
expect('Another instance of vue installed').toHaveBeenWarned()
16+
expect('Another instance of vue installed').not.toHaveBeenWarned()
17+
})
18+
19+
it('should warn install in multiple vue', () => {
20+
try {
21+
const fakeVue = {
22+
version: '2._.x',
23+
config: {
24+
optionMergeStrategies: {},
25+
},
26+
mixin: jest.fn(),
27+
}
28+
29+
// @ts-ignore
30+
CompositionApi.install(fakeVue)
31+
expect('Another instance of vue installed').toHaveBeenWarned()
32+
} finally {
33+
Vue.use(CompositionApi)
34+
expect('Another instance of vue installed').toHaveBeenWarned()
35+
}
1636
})
1737

1838
it('should warn installing multiple times', () => {
@@ -29,7 +49,5 @@ describe('use', () => {
2949
}).toThrowError(
3050
'already installed. Vue.use(VueCompositionAPI) should be called only once.'
3151
)
32-
33-
expect('Another instance of vue installed').toHaveBeenWarned()
3452
})
3553
})

0 commit comments

Comments
 (0)