h.spec.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { h } from '../src/h'
  2. import { createVNode } from '../src/vnode'
  3. // Since h is a thin layer on top of createVNode, we are only testing its
  4. // own logic here. Details of vnode creation is tested in vnode.spec.ts.
  5. describe('renderer: h', () => {
  6. test('type only', () => {
  7. expect(h('div')).toMatchObject(createVNode('div'))
  8. })
  9. test('type + props', () => {
  10. expect(h('div', { id: 'foo' })).toMatchObject(
  11. createVNode('div', { id: 'foo' })
  12. )
  13. })
  14. test('type + omit props', () => {
  15. // array
  16. expect(h('div', ['foo'])).toMatchObject(createVNode('div', null, ['foo']))
  17. // default slot
  18. const slot = () => {}
  19. expect(h('div', slot)).toMatchObject(createVNode('div', null, slot))
  20. // text
  21. expect(h('div', 'foo')).toMatchObject(createVNode('div', null, 'foo'))
  22. })
  23. test('type + props + children', () => {
  24. // array
  25. expect(h('div', {}, ['foo'])).toMatchObject(createVNode('div', {}, ['foo']))
  26. // default slot
  27. const slot = () => {}
  28. expect(h('div', {}, slot)).toMatchObject(createVNode('div', {}, slot))
  29. // text
  30. expect(h('div', {}, 'foo')).toMatchObject(createVNode('div', {}, 'foo'))
  31. })
  32. test('named slots with null props', () => {
  33. const slot = () => {}
  34. expect(
  35. h('div', null, {
  36. foo: slot
  37. })
  38. ).toMatchObject(
  39. createVNode('div', null, {
  40. foo: slot
  41. })
  42. )
  43. })
  44. })