Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks committed Feb 22, 2024
1 parent 76c8ace commit e5e8619
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 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!"
);
}
});
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 e5e8619

Please sign in to comment.