element.spec.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import Vue from 'vue'
  2. import { patch } from 'web/runtime/patch'
  3. import VNode from 'core/vdom/vnode'
  4. describe('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', {}, undefined, undefined, undefined, 'svg')
  13. const elm = patch(null, vnode)
  14. expect(elm.namespaceURI).toBe('http://www.w3.org/2000/svg')
  15. })
  16. it('should warn unknown element', () => {
  17. const vnode = new VNode('unknown')
  18. patch(null, vnode)
  19. expect(`Unknown custom element: <unknown>`).toHaveBeenWarned()
  20. })
  21. it('should warn unknown element with hyphen', () => {
  22. const vnode = new VNode('unknown-foo')
  23. patch(null, vnode)
  24. expect(`Unknown custom element: <unknown-foo>`).toHaveBeenWarned()
  25. })
  26. it('should create an elements which having text content', () => {
  27. const vnode = new VNode('div', {}, [createTextVNode('hello world')])
  28. const elm = patch(null, vnode)
  29. expect(elm.innerHTML).toBe('hello world')
  30. })
  31. it('should create create an elements which having span and text content', () => {
  32. const vnode = new VNode('div', {}, [
  33. new VNode('span'),
  34. createTextVNode('hello world')
  35. ])
  36. const elm = patch(null, vnode)
  37. expect(elm.childNodes[0].tagName).toBe('SPAN')
  38. expect(elm.childNodes[1].textContent).toBe('hello world')
  39. })
  40. it('should create element with scope attribute', () => {
  41. const vnode = new VNode('div')
  42. vnode.context = new Vue({ _scopeId: 'foo' })
  43. vnode.host = new Vue({ _scopeId: 'bar' })
  44. const elm = patch(null, vnode)
  45. expect(elm.hasAttribute('foo')).toBe(true)
  46. expect(elm.hasAttribute('bar')).toBe(true)
  47. })
  48. })