import assert from "node:assert"; import { describe, it } from "node:test"; import { StandaloneReactItem } from "./index"; type TCustomReactItemInstance = StandaloneReactItem & { isRendered: boolean; }; class TStandaloneReact extends StandaloneReactItem { render() { (this as unknown as TCustomReactItemInstance).isRendered = true; } } describe("StandaloneReactItem plugin", () => { it("calls render when element exists", () => { document.body.innerHTML = ""; const el = document.createElement("div"); el.setAttribute("data-js-standalone-react-test", "{}"); document.body.appendChild(el); const item = new TStandaloneReact("[data-js-standalone-react-test]", {}); assert.equal((item as TCustomReactItemInstance).isRendered, true); item.unmount(); }); it("does not throw on unmount when element does not exist", () => { document.body.innerHTML = ""; const item = new TStandaloneReact("[data-js-standalone-react-missing]", {}); assert.doesNotThrow(() => item.unmount()); }); });