element.spec.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 create an elements which having text content', () => {
  17. const vnode = new VNode('div', {}, [createTextVNode('hello world')])
  18. const elm = patch(null, vnode)
  19. expect(elm.innerHTML).toBe('hello world')
  20. })
  21. it('should create create an elements which having span and text content', () => {
  22. const vnode = new VNode('div', {}, [
  23. new VNode('span'),
  24. createTextVNode('hello world')
  25. ])
  26. const elm = patch(null, vnode)
  27. expect(elm.childNodes[0].tagName).toBe('SPAN')
  28. expect(elm.childNodes[1].textContent).toBe('hello world')
  29. })
  30. it('should create element with scope attribute', () => {
  31. const vnode = new VNode('div')
  32. vnode.context = new Vue({ _scopeId: 'foo' })
  33. const elm = patch(null, vnode)
  34. expect(elm.hasAttribute('foo')).toBe(true)
  35. })
  36. })