From 52cf4f7d33e59713a53edebd6bcaf3982b201bd3 Mon Sep 17 00:00:00 2001 From: Thomas V <2619415+tvillaren@users.noreply.github.com> Date: Fri, 2 Jun 2023 15:17:58 +0200 Subject: [PATCH] test: adding failing test case --- src/core/validateGeneratedTypes.test.ts | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/core/validateGeneratedTypes.test.ts b/src/core/validateGeneratedTypes.test.ts index 3d8925da..d446480d 100644 --- a/src/core/validateGeneratedTypes.test.ts +++ b/src/core/validateGeneratedTypes.test.ts @@ -205,4 +205,56 @@ describe("validateGeneratedTypes", () => { expect(errors).toEqual([]); }); + + + it("should handle any", () => { + const sourceTypes = { + sourceText: ` + export interface Citizen { + name: any + }; + `, + relativePath: "source.ts", + }; + + const zodSchemas = { + sourceText: `// Generated by ts-to-zod + import { z } from "zod"; + + export const citizenSchema = z.object({ + name: z.any() + }); + `, + relativePath: "source.zod.ts", + }; + + const integrationTests = { + sourceText: `// Generated by ts-to-zod + import { z } from "zod"; + + import * as spec from "./${sourceTypes.relativePath.slice(0, -3)}"; + import * as generated from "./${zodSchemas.relativePath.slice(0, -3)}"; + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + function expectType(_: T) { + /* noop */ + } + + export type CitizenInferredType = z.infer; + + expectType({} as spec.Citizen); + expectType({} as CitizenInferredType); + `, + relativePath: "source.integration.ts", + }; + + const errors = validateGeneratedTypes({ + sourceTypes, + zodSchemas, + integrationTests, + skipParseJSDoc: false, + }); + + expect(errors).toEqual([]); + }); });