Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: use registered Vue instance for warning
  • Loading branch information
antfu committed Feb 26, 2022
1 parent a33e400 commit b01f1e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/runtimeContext.ts
Expand Up @@ -9,7 +9,7 @@ import {
UnionToIntersection,
isFunction,
} from './utils'
import Vue$1 from 'vue'
import type Vue$1 from 'vue'

let vueDependency: VueConstructor | undefined = undefined

Expand Down
6 changes: 4 additions & 2 deletions src/utils/utils.ts
@@ -1,4 +1,4 @@
import Vue from 'vue'
import { getRegisteredVueOrDefault } from '../runtimeContext'

const toString = (x: any) => Object.prototype.toString.call(x)

Expand Down Expand Up @@ -99,7 +99,9 @@ export function isUndef(v: any): boolean {
}

export function warn(msg: string, vm?: Vue) {
Vue.util.warn(msg, vm)
const Vue = getRegisteredVueOrDefault()
if (!Vue || !Vue.util) console.warn(`[vue-composition-api] ${msg}`)
else Vue.util.warn(msg, vm)
}

export function logError(err: Error, vm: Vue, info: string) {
Expand Down
3 changes: 2 additions & 1 deletion test/v3/runtime-core/apiWatch.spec.ts
Expand Up @@ -8,11 +8,12 @@ import {
shallowReactive,
nextTick,
} from '../../../src'
import Vue from 'vue'
import { getRegisteredVueOrDefault } from '../../../src/runtimeContext'

// reference: https://vue-composition-api-rfc.netlify.com/api.html#watch

describe('api: watch', () => {
const Vue = getRegisteredVueOrDefault()
// const warnSpy = jest.spyOn(console, 'warn');
const warnSpy = jest.spyOn((Vue as any).util, 'warn')

Expand Down

0 comments on commit b01f1e4

Please sign in to comment.