element.spec.js 2.1 KB

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