globalConfig.spec.ts 1.8 KB

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