Files
effect-view/packages/effect-fc-next/test/Refreshable.test.ts
T
Julien Valverdé 462895a3c2
Lint / lint (push) Failing after 1m45s
Add Refreshable trait
2026-07-25 02:02:17 +02:00

41 lines
1.3 KiB
TypeScript

import { describe, expect, it, vi } from "vitest"
import * as Refreshable from "../src/Refreshable.js"
describe("Refreshable", () => {
it("attaches a cell and notifies subscribers after a compatible update", async () => {
const first = {}
const cell = Refreshable.makeCell(first, "hooks", false)
const listener = vi.fn()
expect(Refreshable.isRefreshable(first)).toBe(false)
const attached = Refreshable.attach(first, cell)
expect(attached).toBe(first)
expect(Refreshable.isRefreshable(first)).toBe(true)
expect(attached[Refreshable.RefreshableTypeId]).toBe(cell)
cell.subscribe(listener)
const second = {}
cell.update(second, "hooks", false)
expect(cell.current).toBe(second)
expect(cell.snapshot).toEqual({
revision: 1,
resetRevision: 0,
})
await Promise.resolve()
expect(listener).toHaveBeenCalledTimes(1)
})
it("requests a remount when a signature changes or reset is forced", () => {
const cell = Refreshable.makeCell({}, "one", false)
cell.update({}, "two", false)
expect(cell.snapshot.resetRevision).toBe(1)
cell.update({}, "two", true)
expect(cell.snapshot.resetRevision).toBe(2)
})
})