element.spec.js 2.0 KB

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