Skip to content

Commit

Permalink
test: adding failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tvillaren committed Jun 2, 2023
1 parent 8324ee4 commit 52cf4f7
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/core/validateGeneratedTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(_: T) {
/* noop */
}
export type CitizenInferredType = z.infer<typeof generated.citizenSchema>;
expectType<CitizenInferredType>({} as spec.Citizen);
expectType<spec.Citizen>({} as CitizenInferredType);
`,
relativePath: "source.integration.ts",
};

const errors = validateGeneratedTypes({
sourceTypes,
zodSchemas,
integrationTests,
skipParseJSDoc: false,
});

expect(errors).toEqual([]);
});
});

0 comments on commit 52cf4f7

Please sign in to comment.