2017-04-14 15:19:41 +08:00
|
|
|
import Vue from 'vue'
|
2017-06-14 21:37:26 +08:00
|
|
|
import { formatComponentName, warn } from 'core/util/debug'
|
2017-04-14 15:19:41 +08:00
|
|
|
|
|
|
|
describe('Debug utilities', () => {
|
|
|
|
it('properly format component names', () => {
|
2022-05-05 05:16:17 +08:00
|
|
|
// @ts-expect-error
|
|
|
|
const vm = new Vue()
|
2017-04-14 15:19:41 +08:00
|
|
|
expect(formatComponentName(vm)).toBe('<Root>')
|
|
|
|
|
|
|
|
vm.$root = null
|
|
|
|
vm.$options.name = 'hello-there'
|
|
|
|
expect(formatComponentName(vm)).toBe('<HelloThere>')
|
|
|
|
|
|
|
|
vm.$options.name = null
|
|
|
|
vm.$options._componentTag = 'foo-bar-1'
|
|
|
|
expect(formatComponentName(vm)).toBe('<FooBar1>')
|
|
|
|
|
|
|
|
vm.$options._componentTag = null
|
|
|
|
vm.$options.__file = '/foo/bar/baz/SomeThing.vue'
|
|
|
|
expect(formatComponentName(vm)).toBe(`<SomeThing> at ${vm.$options.__file}`)
|
|
|
|
expect(formatComponentName(vm, false)).toBe('<SomeThing>')
|
|
|
|
|
|
|
|
vm.$options.__file = 'C:\\foo\\bar\\baz\\windows_file.vue'
|
|
|
|
expect(formatComponentName(vm)).toBe(`<WindowsFile> at ${vm.$options.__file}`)
|
|
|
|
expect(formatComponentName(vm, false)).toBe('<WindowsFile>')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('generate correct component hierarchy trace', () => {
|
|
|
|
const one = {
|
|
|
|
name: 'one',
|
|
|
|
render: h => h(two)
|
|
|
|
}
|
|
|
|
const two = {
|
|
|
|
name: 'two',
|
|
|
|
render: h => h(three)
|
|
|
|
}
|
|
|
|
const three = {
|
|
|
|
name: 'three'
|
|
|
|
}
|
|
|
|
new Vue({
|
|
|
|
render: h => h(one)
|
|
|
|
}).$mount()
|
|
|
|
|
|
|
|
expect(
|
2017-12-13 07:42:44 +08:00
|
|
|
`Failed to mount component: template or render function not defined.
|
2017-04-14 15:19:41 +08:00
|
|
|
|
|
|
|
found in
|
|
|
|
|
|
|
|
---> <Three>
|
|
|
|
<Two>
|
|
|
|
<One>
|
|
|
|
<Root>`
|
|
|
|
).toHaveBeenWarned()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('generate correct component hierarchy trace (recursive)', () => {
|
|
|
|
let i = 0
|
|
|
|
const one = {
|
|
|
|
name: 'one',
|
|
|
|
render: h => i++ < 5 ? h(one) : h(two)
|
|
|
|
}
|
|
|
|
const two = {
|
|
|
|
name: 'two',
|
|
|
|
render: h => h(three)
|
|
|
|
}
|
|
|
|
const three = {
|
|
|
|
name: 'three'
|
|
|
|
}
|
|
|
|
new Vue({
|
|
|
|
render: h => h(one)
|
|
|
|
}).$mount()
|
|
|
|
|
|
|
|
expect(
|
2017-12-13 07:42:44 +08:00
|
|
|
`Failed to mount component: template or render function not defined.
|
2017-04-14 15:19:41 +08:00
|
|
|
|
|
|
|
found in
|
|
|
|
|
|
|
|
---> <Three>
|
|
|
|
<Two>
|
|
|
|
<One>... (5 recursive calls)
|
|
|
|
<Root>`
|
|
|
|
).toHaveBeenWarned()
|
|
|
|
})
|
2017-06-14 21:37:26 +08:00
|
|
|
|
|
|
|
describe('warn', () => {
|
|
|
|
const msg = 'message'
|
2022-05-05 05:16:17 +08:00
|
|
|
// @ts-expect-error
|
|
|
|
const vm = new Vue()
|
2017-06-14 21:37:26 +08:00
|
|
|
|
|
|
|
it('calls warnHandler if warnHandler is set', () => {
|
2022-05-20 07:56:02 +08:00
|
|
|
Vue.config.warnHandler = vi.fn()
|
2017-06-14 21:37:26 +08:00
|
|
|
|
|
|
|
warn(msg, vm)
|
|
|
|
|
|
|
|
expect(Vue.config.warnHandler).toHaveBeenCalledWith(msg, vm, jasmine.any(String))
|
|
|
|
|
2022-05-02 04:37:05 +08:00
|
|
|
// @ts-expect-error
|
2017-06-14 21:37:26 +08:00
|
|
|
Vue.config.warnHandler = null
|
|
|
|
})
|
|
|
|
|
|
|
|
it('calls console.error if silent is false', () => {
|
|
|
|
Vue.config.silent = false
|
|
|
|
|
|
|
|
warn(msg, vm)
|
|
|
|
|
|
|
|
expect(msg).toHaveBeenWarned()
|
|
|
|
expect(console.error).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does not call console.error if silent is true', () => {
|
|
|
|
Vue.config.silent = true
|
|
|
|
|
|
|
|
warn(msg, vm)
|
|
|
|
|
|
|
|
expect(console.error).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
Vue.config.silent = false
|
|
|
|
})
|
|
|
|
})
|
2017-04-14 15:19:41 +08:00
|
|
|
})
|