h.spec.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 Component = { template: '<br />' }
  19. const slot = () => {}
  20. expect(h(Component, slot)).toMatchObject(createVNode(Component, null, slot))
  21. // single vnode
  22. const vnode = h('div')
  23. expect(h('div', vnode)).toMatchObject(createVNode('div', null, [vnode]))
  24. // text
  25. expect(h('div', 'foo')).toMatchObject(createVNode('div', null, 'foo'))
  26. })
  27. test('type + props + children', () => {
  28. // array
  29. expect(h('div', {}, ['foo'])).toMatchObject(createVNode('div', {}, ['foo']))
  30. // default slot
  31. const Component = { template: '<br />' }
  32. const slot = () => {}
  33. expect(h(Component, {}, slot)).toMatchObject(
  34. createVNode(Component, {}, slot)
  35. )
  36. // single vnode
  37. const vnode = h('div')
  38. expect(h('div', {}, vnode)).toMatchObject(createVNode('div', {}, [vnode]))
  39. // text
  40. expect(h('div', {}, 'foo')).toMatchObject(createVNode('div', {}, 'foo'))
  41. })
  42. test('named slots with null props', () => {
  43. const Component = { template: '<br />' }
  44. const slot = () => {}
  45. expect(
  46. h(Component, null, {
  47. foo: slot
  48. })
  49. ).toMatchObject(
  50. createVNode(Component, null, {
  51. foo: slot
  52. })
  53. )
  54. })
  55. })