element.spec.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { basePatch as patch } from 'web/runtime/patch'
  2. import VNode from 'core/vdom/vnode'
  3. describe('element', () => {
  4. it('should create an element', () => {
  5. const vnode = new VNode('p', { attrs: { id: '1' }}, [createTextVNode('hello world')])
  6. const elm = patch(null, vnode)
  7. expect(elm.tagName).toBe('P')
  8. expect(elm.outerHTML).toBe('<p id="1">hello world</p>')
  9. })
  10. it('should create an element which having the namespace', () => {
  11. const vnode = new VNode('svg', {}, undefined, undefined, undefined, 'svg')
  12. const elm = patch(null, vnode)
  13. expect(elm.namespaceURI).toBe('http://www.w3.org/2000/svg')
  14. })
  15. it('should create an elements which having text content', () => {
  16. const vnode = new VNode('div', {}, [createTextVNode('hello world')])
  17. const elm = patch(null, vnode)
  18. expect(elm.innerHTML).toBe('hello world')
  19. })
  20. it('should create create an elements which having span and text content', () => {
  21. const vnode = new VNode('div', {}, [
  22. new VNode('span'),
  23. createTextVNode('hello world')
  24. ])
  25. const elm = patch(null, vnode)
  26. expect(elm.childNodes[0].tagName).toBe('SPAN')
  27. expect(elm.childNodes[1].textContent).toBe('hello world')
  28. })
  29. })