debug.spec.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import Vue from 'vue'
  2. import { formatComponentName } from 'core/util/debug'
  3. describe('Debug utilities', () => {
  4. it('properly format component names', () => {
  5. const vm = new Vue()
  6. expect(formatComponentName(vm)).toBe('<Root>')
  7. vm.$root = null
  8. vm.$options.name = 'hello-there'
  9. expect(formatComponentName(vm)).toBe('<HelloThere>')
  10. vm.$options.name = null
  11. vm.$options._componentTag = 'foo-bar-1'
  12. expect(formatComponentName(vm)).toBe('<FooBar1>')
  13. vm.$options._componentTag = null
  14. vm.$options.__file = '/foo/bar/baz/SomeThing.vue'
  15. expect(formatComponentName(vm)).toBe(`<SomeThing> at ${vm.$options.__file}`)
  16. expect(formatComponentName(vm, false)).toBe('<SomeThing>')
  17. vm.$options.__file = 'C:\\foo\\bar\\baz\\windows_file.vue'
  18. expect(formatComponentName(vm)).toBe(`<WindowsFile> at ${vm.$options.__file}`)
  19. expect(formatComponentName(vm, false)).toBe('<WindowsFile>')
  20. })
  21. it('generate correct component hierarchy trace', () => {
  22. const one = {
  23. name: 'one',
  24. render: h => h(two)
  25. }
  26. const two = {
  27. name: 'two',
  28. render: h => h(three)
  29. }
  30. const three = {
  31. name: 'three'
  32. }
  33. new Vue({
  34. render: h => h(one)
  35. }).$mount()
  36. expect(
  37. `Failed to mount component: template or render function not defined.
  38. found in
  39. ---> <Three>
  40. <Two>
  41. <One>
  42. <Root>`
  43. ).toHaveBeenWarned()
  44. })
  45. it('generate correct component hierarchy trace (recursive)', () => {
  46. let i = 0
  47. const one = {
  48. name: 'one',
  49. render: h => i++ < 5 ? h(one) : h(two)
  50. }
  51. const two = {
  52. name: 'two',
  53. render: h => h(three)
  54. }
  55. const three = {
  56. name: 'three'
  57. }
  58. new Vue({
  59. render: h => h(one)
  60. }).$mount()
  61. expect(
  62. `Failed to mount component: template or render function not defined.
  63. found in
  64. ---> <Three>
  65. <Two>
  66. <One>... (5 recursive calls)
  67. <Root>`
  68. ).toHaveBeenWarned()
  69. })
  70. })