toast-owner.test.ts 800 B

1234567891011121314151617181920212223242526
  1. import { describe, expect, test } from "bun:test"
  2. import { createSignal, type JSX } from "solid-js"
  3. import { showToastV2, toasterV2 } from "@opencode-ai/ui/v2/toast-v2"
  4. describe("showToastV2", () => {
  5. test("creates no reactive computations at call time", () => {
  6. const [tick, setTick] = createSignal(0)
  7. let reads = 0
  8. const icon = (() => {
  9. reads++
  10. tick()
  11. return undefined
  12. }) as unknown as JSX.Element
  13. const id = showToastV2({ description: "test", icon })
  14. // Resolving the icon at call time creates an ownerless computation that is
  15. // never disposed and tracks its dependencies forever; it must only resolve
  16. // once the toast component renders.
  17. expect(reads).toBe(0)
  18. setTick(1)
  19. expect(reads).toBe(0)
  20. toasterV2.dismiss(id)
  21. })
  22. })