defineSlots.spec.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { assertCode, compileSFCScript as compile } from '../utils'
  2. describe('defineSlots()', () => {
  3. test('basic usage', () => {
  4. const { content } = compile(`
  5. <script setup lang="ts">
  6. const slots = defineSlots<{
  7. default: { msg: string }
  8. }>()
  9. </script>
  10. `)
  11. assertCode(content)
  12. expect(content).toMatch(`const slots = _useSlots()`)
  13. expect(content).not.toMatch('defineSlots')
  14. })
  15. test('w/o return value', () => {
  16. const { content } = compile(`
  17. <script setup lang="ts">
  18. defineSlots<{
  19. default: { msg: string }
  20. }>()
  21. </script>
  22. `)
  23. assertCode(content)
  24. expect(content).not.toMatch('defineSlots')
  25. expect(content).not.toMatch(`_useSlots`)
  26. })
  27. test('w/o generic params', () => {
  28. const { content } = compile(`
  29. <script setup>
  30. const slots = defineSlots()
  31. </script>
  32. `)
  33. assertCode(content)
  34. expect(content).toMatch(`const slots = _useSlots()`)
  35. expect(content).not.toMatch('defineSlots')
  36. })
  37. })