import {
memberRefkey,
namekey,
Output,
refkey,
StatementList,
} from "@alloy-js/core";
import { expect, it } from "vitest";
import * as ts from "../src/index.js";
it("works", () => {
expect(
,
).toRenderTo("const hi = 12;");
});
it("allows omitting the initializer", () => {
expect(
,
).toRenderTo("let hi;");
});
it("takes namekeys", () => {
expect(
,
).toRenderTo("const foo = 12;");
});
it("works end-to-end", () => {
const TestType = refkey("TestType");
expect(
,
).toRenderTo({
"types.ts": `
type TestType = "hello" | "goodbye";
`,
"test.ts": `
import type { TestType } from "./types.js";
export let hi: TestType = "hello";
`,
});
});
it("instantiates symbols from its type", () => {
const ifaceRk = refkey();
const ifaceMemberRk = refkey();
const classRk = refkey();
const classMemberRk = refkey();
const v1Rk = refkey();
const v2Rk = refkey();
expect(
,
).toRenderTo({
"decl.ts": `
interface Foo {
instanceProp: 42;
}class Bar {
instanceProp = 42;
}
`,
"inst.ts": `
import type { Bar, Foo } from "./decl.js";
export const one: Bar = "test";
one.instanceProp;
export const two: Foo = "test";
two.instanceProp;
`,
});
});
it("instantiates symbols from type even when an expression is passed", () => {
const classRk = refkey();
const classMemberRk = refkey();
const v1Rk = refkey();
expect(
,
).toRenderTo({
"decl.ts": `
class Bar {
instanceProp = 42;
}
`,
"inst.ts": `
import type { Bar } from "./decl.js";
export const one: Bar = {
noProp: 1
};
one.instanceProp;
`,
});
});