import {
  cleanup,
  render,
} from "@testing-library/react";
import assert from "node:assert";
import {
  afterEach,
  describe,
  test,
} from "node:test";
import { HTMLComment } from "./index";

describe("HTMLComment", () => {
  afterEach(() => {
    cleanup();
  });

  test("renders template node with comment marker", () => {
    const { container } = render(<HTMLComment text={"build:meta"} />);

    const template = container.querySelector("template");
    assert.notStrictEqual(template, null);
    assert.strictEqual(template?.getAttribute("data-comment"), "build:meta");
    assert.strictEqual(template?.innerHTML, "");
  });

  test("passes extra attributes to template node", () => {
    const { container } = render(
      <HTMLComment
        text={"meta"}
        extraAttrs={{ "data-testid": "html-comment" }}
      />
    );

    assert.notStrictEqual(container.querySelector("template[data-testid='html-comment']"), null);
  });
});
