Skip to content

Commit

Permalink
a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lostfictions committed Dec 12, 2022
1 parent d0be1c6 commit 75cc586
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/parse-env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,4 +540,31 @@ describe("parseCore", () => {

expect(() => parseEnv({}, { DEPRECATED: z.undefined() })).not.toThrow();
});

it("handles a schema with refinement type", () => {
const schema = {
AT_LEAST_FIVE_WORDS: z.string().refine((s) => s.split(" ").length >= 5),
};

expect(() =>
parseEnv({ AT_LEAST_FIVE_WORDS: "only four words here" }, schema)
).toThrow();

expect(() =>
parseEnv({ AT_LEAST_FIVE_WORDS: "but there's five words here!" }, schema)
).not.toThrow();
});

it("handles a schema that transforms the result", () => {
const res = parseEnv(
{
wordList: "hello there friends",
},
{
wordList: z.string().transform((s) => s.split(" ")),
}
);

expect(res).toStrictEqual({ wordList: ["hello", "there", "friends"] });
});
});

0 comments on commit 75cc586

Please sign in to comment.