import assert from "node:assert/strict"; import { describe, it, mock } from "node:test"; import { setupRef } from "./setupRef"; describe("setupRef", () => { it("updates object ref with element and null", () => { const ref: { current: HTMLElement | null; } = { current: document.createElement("div"), }; const setRef = setupRef(ref); const nextNode = document.createElement("span"); setRef(nextNode); assert.strictEqual(ref.current, nextNode); setRef(null); assert.strictEqual(ref.current, null); }); it("calls callback ref with element and null", () => { const callbackRef = mock.fn(); const setRef = setupRef(callbackRef); const nextNode = document.createElement("span"); setRef(nextNode); setRef(null); assert.strictEqual(callbackRef.mock.calls.length, 2); assert.strictEqual(callbackRef.mock.calls[0]?.arguments[0], nextNode); assert.strictEqual(callbackRef.mock.calls[1]?.arguments[0], null); }); });