import type { Refkey } from "@alloy-js/core";
import { List } from "@alloy-js/core";
import { d } from "@alloy-js/core/testing";
import { expect, it } from "vitest";
import {
ClassDeclaration,
ClassField,
ClassMethod,
} from "#components/index.js";
import { createTSTestWrapper } from "./create-wrapper.jsx";
it("should render defkey inline", async () => {
const { Wrapper, defkey } = createTSTestWrapper();
expect(return {defkey("myResult")};).toRenderTo(
`return myResult;`,
);
});
it("reuses declarations across multiple usage sites", () => {
const { Wrapper, defkey } = createTSTestWrapper();
const T = defkey("Thing");
const R = defkey("Result");
expect(
,
).toRenderTo(d`
class A {
a(x: Thing): Result {}
b(y: Thing): Result {}
}`);
});
it("reuses declarations across multiple defkeys", () => {
const { Wrapper, defkey } = createTSTestWrapper();
expect(
,
).toRenderTo(d`
class A {
a(x: Thing): Result {}
b(y: Thing): Result {}
}`);
});
it("should render defkey in nested component", async () => {
function TestComponent(props: { returnTypeRef: Refkey }) {
return ;
}
const { Wrapper, defkey } = createTSTestWrapper();
expect(
,
).toRenderTo(d`
class MyClass {
foo(): MyType {}
}`);
});
it("should render defkey in class property", async () => {
const { Wrapper, defkey } = createTSTestWrapper();
expect(
,
).toRenderTo(d`
class TestClass {
MyProperty: MyType
}`);
});