1
0

slots.test.tsx 846 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 registry = createSolidSlotRegistry<Slots>(useRenderer(), {})
  18. const Slot = createSlot(registry)
  19. registry.register({ id: "plugin", slots: { prompt: () => <Probe /> } })
  20. return (
  21. <Slot name="prompt" mode="replace">
  22. <box />
  23. </Slot>
  24. )
  25. }
  26. const app = await testRender(() => <App />)
  27. try {
  28. expect(mounts).toBe(1)
  29. } finally {
  30. app.renderer.destroy()
  31. }
  32. })