Skip to content

Commit

Permalink
test: add test to cover issue fabien0102#140
Browse files Browse the repository at this point in the history
  • Loading branch information
tvillaren committed Sep 22, 2023
1 parent d57b810 commit 21142c1
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/core/validateGeneratedTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,56 @@ describe("validateGeneratedTypes", () => {
expect(errors).toEqual([]);
});

it("should return no error if we use a non-optional any", () => {
const sourceTypes = {
sourceText: `
export interface Citizen {
villain: any;
};
`,
relativePath: "source.ts",
};

const zodSchemas = {
sourceText: `// Generated by ts-to-zod
import { z } from "zod";
export const citizenSchema = z.object({
villain: 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([]);
});

it("should return an error if the types doesn't match", () => {
const sourceTypes = {
sourceText: `
Expand Down

0 comments on commit 21142c1

Please sign in to comment.