globalConfig.spec.ts 2.0 KB

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