components.spec.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import Vue from 'vue'
  2. import { UA } from 'core/util/env'
  3. describe('Options components', () => {
  4. it('should accept plain object', () => {
  5. const vm = new Vue({
  6. template: '<test></test>',
  7. components: {
  8. test: {
  9. template: '<div>hi</div>'
  10. }
  11. }
  12. }).$mount()
  13. expect(vm.$el.tagName).toBe('DIV')
  14. expect(vm.$el.textContent).toBe('hi')
  15. })
  16. it('should accept extended constructor', () => {
  17. const Test = Vue.extend({
  18. template: '<div>hi</div>'
  19. })
  20. const vm = new Vue({
  21. template: '<test></test>',
  22. components: {
  23. test: Test
  24. }
  25. }).$mount()
  26. expect(vm.$el.tagName).toBe('DIV')
  27. expect(vm.$el.textContent).toBe('hi')
  28. })
  29. it('should accept camelCase', () => {
  30. const myComp = {
  31. template: '<div>hi</div>'
  32. }
  33. const vm = new Vue({
  34. template: '<my-comp></my-comp>',
  35. components: {
  36. myComp
  37. }
  38. }).$mount()
  39. expect(vm.$el.tagName).toBe('DIV')
  40. expect(vm.$el.textContent).toBe('hi')
  41. })
  42. it('should accept PascalCase', () => {
  43. const MyComp = {
  44. template: '<div>hi</div>'
  45. }
  46. const vm = new Vue({
  47. template: '<my-comp></my-comp>',
  48. components: {
  49. MyComp
  50. }
  51. }).$mount()
  52. expect(vm.$el.tagName).toBe('DIV')
  53. expect(vm.$el.textContent).toBe('hi')
  54. })
  55. it('should warn native HTML elements', () => {
  56. new Vue({
  57. components: {
  58. div: { template: '<div></div>' }
  59. }
  60. })
  61. expect('Do not use built-in or reserved HTML elements as component').toHaveBeenWarned()
  62. })
  63. it('should warn built-in elements', () => {
  64. new Vue({
  65. components: {
  66. component: { template: '<div></div>' }
  67. }
  68. })
  69. expect('Do not use built-in or reserved HTML elements as component').toHaveBeenWarned()
  70. })
  71. // the HTMLUnknownElement check doesn't work in Android 4.2
  72. // but since it doesn't support custom elements nor will any dev use it
  73. // as their primary debugging browser, it doesn't really matter.
  74. if (!(UA && /android 4\.2/.test(UA))) {
  75. it('warn non-existent', () => {
  76. new Vue({
  77. template: '<test></test>'
  78. }).$mount()
  79. expect('Unknown custom element: <test>').toHaveBeenWarned()
  80. })
  81. }
  82. })