config.spec.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import Vue from 'vue'
  2. import { warn } from 'core/util/debug'
  3. describe('Global config', () => {
  4. it('should warn replacing config object', () => {
  5. const originalConfig = Vue.config
  6. Vue.config = {}
  7. expect(Vue.config).toBe(originalConfig)
  8. expect('Do not replace the Vue.config object').toHaveBeenWarned()
  9. })
  10. describe('silent', () => {
  11. it('should be false by default', () => {
  12. warn('foo')
  13. expect('foo').toHaveBeenWarned()
  14. })
  15. it('should work when set to true', () => {
  16. Vue.config.silent = true
  17. warn('foo')
  18. expect('foo').not.toHaveBeenWarned()
  19. Vue.config.silent = false
  20. })
  21. })
  22. describe('optionMergeStrategies', () => {
  23. it('should allow defining custom option merging strategies', () => {
  24. const spy = vi.fn()
  25. Vue.config.optionMergeStrategies.__test__ = (parent, child, vm) => {
  26. spy(parent, child, vm)
  27. return child + 1
  28. }
  29. const Test = Vue.extend({
  30. __test__: 1
  31. })
  32. expect(spy.mock.calls.length).toBe(1)
  33. expect(spy).toHaveBeenCalledWith(undefined, 1, undefined)
  34. expect(Test.options.__test__).toBe(2)
  35. const test = new Test({
  36. __test__: 2
  37. })
  38. expect(spy.mock.calls.length).toBe(2)
  39. expect(spy).toHaveBeenCalledWith(2, 2, test)
  40. expect(test.$options.__test__).toBe(3)
  41. })
  42. })
  43. describe('ignoredElements', () => {
  44. it('should work', () => {
  45. Vue.config.ignoredElements = ['foo', /^ion-/]
  46. new Vue({
  47. template: `<div><foo/><ion-foo/><ion-bar/></div>`
  48. }).$mount()
  49. expect('Unknown custom element').not.toHaveBeenWarned()
  50. Vue.config.ignoredElements = []
  51. })
  52. })
  53. describe('async', () => {
  54. it('does not update synchronously when true', () => {
  55. const spy = vi.fn()
  56. const vm = new Vue({
  57. template: `<div :class="value"></div>`,
  58. updated: spy,
  59. data: { value: true }
  60. }).$mount()
  61. vm.value = false
  62. expect(spy).not.toHaveBeenCalled()
  63. })
  64. it('updates synchronously when false', () => {
  65. const spy = vi.fn()
  66. Vue.config.async = false
  67. const vm = new Vue({
  68. template: `<div :class="value"></div>`,
  69. updated: spy,
  70. data: { value: true }
  71. }).$mount()
  72. vm.value = false
  73. expect(spy).toHaveBeenCalled()
  74. Vue.config.async = true
  75. })
  76. it('runs watchers in correct order when false', () => {
  77. Vue.config.async = false
  78. const vm = new Vue({
  79. template: `
  80. <div id="app">
  81. {{ computed }}
  82. </div>`,
  83. props: ['prop'],
  84. propsData: {
  85. prop: []
  86. },
  87. data: () => ({
  88. data: ''
  89. }),
  90. computed: {
  91. computed() {
  92. return this.prop.join(',')
  93. }
  94. },
  95. watch: {
  96. prop: 'execute'
  97. },
  98. methods: {
  99. execute() {
  100. this.data = this.computed
  101. }
  102. }
  103. }).$mount()
  104. expect(vm.computed).toBe('')
  105. expect(vm.data).toBe('')
  106. vm.prop = [1, 2, 3]
  107. expect(vm.computed).toBe('1,2,3')
  108. expect(vm.data).toBe('1,2,3')
  109. vm.prop.push(4, 5)
  110. expect(vm.computed).toBe('1,2,3,4,5')
  111. expect(vm.data).toBe('1,2,3,4,5')
  112. Vue.config.async = true
  113. })
  114. })
  115. })