Skip to content

Commit

Permalink
test: adding new test
Browse files Browse the repository at this point in the history
  • Loading branch information
tvillaren committed Sep 8, 2023
1 parent 61ca286 commit a288570
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/core/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,37 @@ describe("generate", () => {
`);
});
});

describe("import as array of union of imported types", () => {
const sourceText = `
import { Hero } from "module"
import { Villain } from "module"
export type Person = (Hero | Villain)[]
`;

const { getZodSchemasFile } = generate({
sourceText,
});

it("should generate the zod schemas", () => {
expect(getZodSchemasFile("./source")).toMatchInlineSnapshot(`
"// Generated by ts-to-zod
import { z } from \\"zod\\";
import { Hero } from \\"module\\";
import { Villain } from \\"module\\";
const heroSchema = z.instanceof(Hero);
const villainSchema = z.instanceof(Villain);
export const personSchema = z.array(z.union([heroSchema, villainSchema]));
"
`);
});
});
});

describe("with input/output mappings to manage imports", () => {
Expand Down

0 comments on commit a288570

Please sign in to comment.