Skip to content

Commit

Permalink
style: lint with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandollisboa committed Feb 20, 2024
1 parent ce4ec5a commit 1e29cea
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
18 changes: 13 additions & 5 deletions deno/lib/__tests__/enum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,27 @@ test("extract/exclude", () => {
util.assertEqual<z.infer<typeof EmptyFoodEnum>, never>(true);
});

test('error map in extract/exclude', () => {
test("error map in extract/exclude", () => {
const foods = ["Pasta", "Pizza", "Tacos", "Burgers", "Salad"] as const;
const FoodEnum = z.enum(foods, { errorMap: () => ({ message: "This is not food!" }) });
const FoodEnum = z.enum(foods, {
errorMap: () => ({ message: "This is not food!" }),
});
const ItalianEnum = FoodEnum.extract(["Pasta", "Pizza"]);
const foodsError = FoodEnum.safeParse("Cucumbers");
const italianError = ItalianEnum.safeParse("Tacos");
if (!foodsError.success && !italianError.success) {
expect(foodsError.error.issues[0].message).toEqual(italianError.error.issues[0].message);
expect(foodsError.error.issues[0].message).toEqual(
italianError.error.issues[0].message
);
}

const UnhealthyEnum = FoodEnum.exclude(["Salad"], { errorMap: () => ({ message: "This is not healthy food!" }) });
const UnhealthyEnum = FoodEnum.exclude(["Salad"], {
errorMap: () => ({ message: "This is not healthy food!" }),
});
const unhealthyError = UnhealthyEnum.safeParse("Salad");
if (!unhealthyError.success) {
expect(unhealthyError.error.issues[0].message).toEqual("This is not healthy food!");
expect(unhealthyError.error.issues[0].message).toEqual(
"This is not healthy food!"
);
}
});
2 changes: 1 addition & 1 deletion deno/lib/__tests__/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ test("enum with message returns the custom error message", () => {
);
}
});

test("when the message is falsy, it is used as is provided", () => {
const schema = z.string().max(1, { message: "" });
const result = schema.safeParse("asdf");
Expand Down
18 changes: 13 additions & 5 deletions src/__tests__/enum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,27 @@ test("extract/exclude", () => {
util.assertEqual<z.infer<typeof EmptyFoodEnum>, never>(true);
});

test('error map in extract/exclude', () => {
test("error map in extract/exclude", () => {
const foods = ["Pasta", "Pizza", "Tacos", "Burgers", "Salad"] as const;
const FoodEnum = z.enum(foods, { errorMap: () => ({ message: "This is not food!" }) });
const FoodEnum = z.enum(foods, {
errorMap: () => ({ message: "This is not food!" }),
});
const ItalianEnum = FoodEnum.extract(["Pasta", "Pizza"]);
const foodsError = FoodEnum.safeParse("Cucumbers");
const italianError = ItalianEnum.safeParse("Tacos");
if (!foodsError.success && !italianError.success) {
expect(foodsError.error.issues[0].message).toEqual(italianError.error.issues[0].message);
expect(foodsError.error.issues[0].message).toEqual(
italianError.error.issues[0].message
);
}

const UnhealthyEnum = FoodEnum.exclude(["Salad"], { errorMap: () => ({ message: "This is not healthy food!" }) });
const UnhealthyEnum = FoodEnum.exclude(["Salad"], {
errorMap: () => ({ message: "This is not healthy food!" }),
});
const unhealthyError = UnhealthyEnum.safeParse("Salad");
if (!unhealthyError.success) {
expect(unhealthyError.error.issues[0].message).toEqual("This is not healthy food!");
expect(unhealthyError.error.issues[0].message).toEqual(
"This is not healthy food!"
);
}
});

0 comments on commit 1e29cea

Please sign in to comment.