element.spec.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import Vue from 'vue'
  2. import { patch } from 'web/runtime/patch'
  3. import VNode from 'core/vdom/vnode'
  4. describe('vdom patch: element', () => {
  5. it('should create an element', () => {
  6. const vnode = new VNode('p', { attrs: { id: '1' } }, [
  7. createTextVNode('hello world')
  8. ])
  9. const elm = patch(null, vnode)
  10. expect(elm.tagName).toBe('P')
  11. expect(elm.outerHTML).toBe('<p id="1">hello world</p>')
  12. })
  13. it('should create an element which having the namespace', () => {
  14. const vnode = new VNode('svg', {})
  15. vnode.ns = 'svg'
  16. const elm = patch(null, vnode)
  17. expect(elm.namespaceURI).toBe('http://www.w3.org/2000/svg')
  18. })
  19. const el = document.createElement('unknown')
  20. // Android Browser <= 4.2 doesn't use correct class name,
  21. // but it doesn't matter because no one's gonna use it as their primary
  22. // development browser.
  23. if (/HTMLUnknownElement/.test(el.toString())) {
  24. it('should warn unknown element', () => {
  25. const vnode = new VNode('unknown')
  26. patch(null, vnode)
  27. expect(`Unknown custom element: <unknown>`).toHaveBeenWarned()
  28. })
  29. }
  30. it('should warn unknown element with hyphen', () => {
  31. const vnode = new VNode('unknown-foo')
  32. patch(null, vnode)
  33. expect(`Unknown custom element: <unknown-foo>`).toHaveBeenWarned()
  34. })
  35. it('should create an elements which having text content', () => {
  36. const vnode = new VNode('div', {}, [createTextVNode('hello world')])
  37. const elm = patch(null, vnode)
  38. expect(elm.innerHTML).toBe('hello world')
  39. })
  40. it('should create an elements which having span and text content', () => {
  41. const vnode = new VNode('div', {}, [
  42. new VNode('span'),
  43. createTextVNode('hello world')
  44. ])
  45. const elm = patch(null, vnode)
  46. expect(elm.childNodes[0].tagName).toBe('SPAN')
  47. expect(elm.childNodes[1].textContent).toBe('hello world')
  48. })
  49. it('should create element with scope attribute', () => {
  50. const vnode = new VNode('div')
  51. vnode.context = new Vue({ _scopeId: 'foo' })
  52. const elm = patch(null, vnode)
  53. expect(elm.hasAttribute('foo')).toBe(true)
  54. })
  55. })