Skip to content

Commit c1a1e2d

Browse files
Jeong-jjblack7375
andcommitted
Test: RuntimeFn Type Test
Co-authored-by: alstjr7375 <alstjr7375@daum.net>
1 parent 8a89aac commit c1a1e2d

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

packages/css/src/rules/types.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export type RecipeVariants<RecipeFn extends RuntimeFn<VariantGroups>> =
108108

109109
// == Tests ====================================================================
110110
if (import.meta.vitest) {
111-
const { describe, it, assertType } = import.meta.vitest;
111+
const { describe, it, assertType, expectTypeOf } = import.meta.vitest;
112112

113113
describe.concurrent("ConditionVariants Type Test", () => {
114114
it("Conditional Type", () => {
@@ -239,6 +239,59 @@ if (import.meta.vitest) {
239239
});
240240
});
241241

242+
describe.concurrent("RuntimeFn Type Test", () => {
243+
type TestVariantsType = {
244+
color: {
245+
brand: { color: string };
246+
accent: { color: string };
247+
};
248+
size: {
249+
small: { padding: number };
250+
medium: { padding: number };
251+
large: { padding: number };
252+
};
253+
outlined: {
254+
true: { border: string };
255+
false: { border: string };
256+
};
257+
};
258+
259+
it("RuntimeFn Type Check", () => {
260+
type ExpectedResultType = RuntimeFn<TestVariantsType>;
261+
expectTypeOf<ExpectedResultType>().toBeFunction();
262+
expectTypeOf<ExpectedResultType["variants"]>().toBeFunction();
263+
expectTypeOf<ExpectedResultType["classNames"]>().toBeObject();
264+
265+
const expectedResult = Object.assign(
266+
(_options?: ResolveComplex<VariantSelection<TestVariantsType>>) =>
267+
"my-class",
268+
{
269+
variants: () =>
270+
["color", "size", "outlined"] satisfies (keyof TestVariantsType)[],
271+
classNames: {
272+
base: "basic-class",
273+
variants: {
274+
color: {
275+
brand: "color-brand",
276+
accent: "color-accent"
277+
},
278+
size: {
279+
small: "size-small",
280+
medium: "size-medium",
281+
large: "size-large"
282+
},
283+
outlined: {
284+
true: "outlined-true",
285+
false: "outlined-false"
286+
}
287+
}
288+
} satisfies RecipeClassNames<TestVariantsType>
289+
}
290+
);
291+
assertType<ExpectedResultType>(expectedResult);
292+
});
293+
});
294+
242295
describe.concurrent("Types related to Rules", () => {
243296
function assertValidOptions<
244297
Variants extends VariantGroups | undefined = undefined,

0 commit comments

Comments
 (0)