rendererElement.spec.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {
  2. type TestElement,
  3. h,
  4. serializeInner as inner,
  5. nodeOps,
  6. render,
  7. } from '@vue/runtime-test'
  8. describe('renderer: element', () => {
  9. let root: TestElement
  10. beforeEach(() => {
  11. root = nodeOps.createElement('div')
  12. })
  13. it('should create an element', () => {
  14. render(h('div'), root)
  15. expect(inner(root)).toBe('<div></div>')
  16. })
  17. it('should create an element with props', () => {
  18. render(h('div', { id: 'foo', class: 'bar' }), root)
  19. expect(inner(root)).toBe('<div id="foo" class="bar"></div>')
  20. })
  21. it('should create an element with direct text children', () => {
  22. render(h('div', ['foo', ' ', 'bar']), root)
  23. expect(inner(root)).toBe('<div>foo bar</div>')
  24. })
  25. it('should create an element with direct text children and props', () => {
  26. render(h('div', { id: 'foo' }, ['bar']), root)
  27. expect(inner(root)).toBe('<div id="foo">bar</div>')
  28. })
  29. it('should update an element tag which is already mounted', () => {
  30. render(h('div', ['foo']), root)
  31. expect(inner(root)).toBe('<div>foo</div>')
  32. render(h('span', ['foo']), root)
  33. expect(inner(root)).toBe('<span>foo</span>')
  34. })
  35. it('should update element props which is already mounted', () => {
  36. render(h('div', { id: 'bar' }, ['foo']), root)
  37. expect(inner(root)).toBe('<div id="bar">foo</div>')
  38. render(h('div', { id: 'baz', class: 'bar' }, ['foo']), root)
  39. expect(inner(root)).toBe('<div id="baz" class="bar">foo</div>')
  40. })
  41. })