globalConfig.spec.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { vi } from 'vitest'
  2. import Vue from '@vue/compat'
  3. import {
  4. DeprecationTypes,
  5. toggleDeprecationWarning
  6. } from '../../runtime-core/src/compat/compatConfig'
  7. import { createApp } from '../src/esm-index'
  8. import { triggerEvent } from './utils'
  9. beforeEach(() => {
  10. toggleDeprecationWarning(false)
  11. Vue.configureCompat({ MODE: 2 })
  12. })
  13. afterEach(() => {
  14. Vue.configureCompat({ MODE: 3 })
  15. toggleDeprecationWarning(false)
  16. })
  17. // only testing config options that affect runtime behavior.
  18. test('GLOBAL_KEY_CODES', () => {
  19. Vue.config.keyCodes = {
  20. foo: 86,
  21. bar: [38, 87]
  22. }
  23. const onFoo = vi.fn()
  24. const onBar = vi.fn()
  25. const el = document.createElement('div')
  26. new Vue({
  27. el,
  28. template: `<input type="text" @keyup.foo="onFoo" @keyup.bar="onBar">`,
  29. methods: {
  30. onFoo,
  31. onBar
  32. }
  33. })
  34. triggerEvent(el.children[0], 'keyup', e => {
  35. e.key = '_'
  36. e.keyCode = 86
  37. })
  38. expect(onFoo).toHaveBeenCalledTimes(1)
  39. expect(onBar).toHaveBeenCalledTimes(0)
  40. triggerEvent(el.children[0], 'keyup', e => {
  41. e.key = '_'
  42. e.keyCode = 38
  43. })
  44. expect(onFoo).toHaveBeenCalledTimes(1)
  45. expect(onBar).toHaveBeenCalledTimes(1)
  46. triggerEvent(el.children[0], 'keyup', e => {
  47. e.key = '_'
  48. e.keyCode = 87
  49. })
  50. expect(onFoo).toHaveBeenCalledTimes(1)
  51. expect(onBar).toHaveBeenCalledTimes(2)
  52. })
  53. test('GLOBAL_IGNORED_ELEMENTS', () => {
  54. Vue.config.ignoredElements = [/^v-/, 'foo']
  55. const el = document.createElement('div')
  56. new Vue({
  57. el,
  58. template: `<v-foo/><foo/>`
  59. })
  60. expect(el.innerHTML).toBe(`<v-foo></v-foo><foo></foo>`)
  61. })
  62. test('singleton config should affect apps created with createApp()', () => {
  63. Vue.config.ignoredElements = [/^v-/, 'foo']
  64. const el = document.createElement('div')
  65. createApp({
  66. template: `<v-foo/><foo/>`
  67. }).mount(el)
  68. expect(el.innerHTML).toBe(`<v-foo></v-foo><foo></foo>`)
  69. })
  70. test('config.optionMergeStrategies', () => {
  71. toggleDeprecationWarning(true)
  72. expect(typeof Vue.config.optionMergeStrategies.created).toBe('function')
  73. expect(DeprecationTypes.CONFIG_OPTION_MERGE_STRATS).toHaveBeenWarned()
  74. })