slot-replace.test.tsx 884 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /** @jsxImportSource @opentui/solid */
  2. import { expect, test } from "bun:test"
  3. import { createSlot, createSolidSlotRegistry, testRender, useRenderer } from "@opentui/solid"
  4. import { onMount } from "solid-js"
  5. type Slots = {
  6. prompt: {}
  7. }
  8. test("replace slot mounts plugin content once", async () => {
  9. let mounts = 0
  10. const Probe = () => {
  11. onMount(() => {
  12. mounts += 1
  13. })
  14. return <box />
  15. }
  16. const App = () => {
  17. const renderer = useRenderer()
  18. const reg = createSolidSlotRegistry<Slots>(renderer, {})
  19. const Slot = createSlot(reg)
  20. reg.register({
  21. id: "plugin",
  22. slots: {
  23. prompt() {
  24. return <Probe />
  25. },
  26. },
  27. })
  28. return (
  29. <box>
  30. <Slot name="prompt" mode="replace">
  31. <box />
  32. </Slot>
  33. </box>
  34. )
  35. }
  36. await testRender(() => <App />)
  37. expect(mounts).toBe(1)
  38. })