Skip to content
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

fix(vue-test): prevent warning when using multiple localVue #531

Merged
merged 1 commit into from
Sep 18, 2020
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: 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()
})
})