Files
klz-cables.com/.pnpm-store/v10/files/4d/a666c7a1be37b8922164cce066a46c09c118521a05d21fa36f775206c1215529258f943c3064c233fb96ba72e41e1a8353fcaa51020f4f453eee6f8755b61e
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

134 lines
3.7 KiB
Plaintext

// @ts-ignore TS6133
import { expect, test } from "vitest";
import * as z from "zod/v3";
test("array min", async () => {
try {
await z.array(z.string()).min(4).parseAsync([]);
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("Array must contain at least 4 element(s)");
}
});
test("array max", async () => {
try {
await z.array(z.string()).max(2).parseAsync(["asdf", "asdf", "asdf"]);
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("Array must contain at most 2 element(s)");
}
});
test("array length", async () => {
try {
await z.array(z.string()).length(2).parseAsync(["asdf", "asdf", "asdf"]);
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("Array must contain exactly 2 element(s)");
}
try {
await z.array(z.string()).length(2).parseAsync(["asdf"]);
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("Array must contain exactly 2 element(s)");
}
});
test("string length", async () => {
try {
await z.string().length(4).parseAsync("asd");
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("String must contain exactly 4 character(s)");
}
try {
await z.string().length(4).parseAsync("asdaa");
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("String must contain exactly 4 character(s)");
}
});
test("string min", async () => {
try {
await z.string().min(4).parseAsync("asd");
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("String must contain at least 4 character(s)");
}
});
test("string max", async () => {
try {
await z.string().max(4).parseAsync("aasdfsdfsd");
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("String must contain at most 4 character(s)");
}
});
test("number min", async () => {
try {
await z.number().gte(3).parseAsync(2);
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("Number must be greater than or equal to 3");
}
});
test("number max", async () => {
try {
await z.number().lte(3).parseAsync(4);
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("Number must be less than or equal to 3");
}
});
test("number nonnegative", async () => {
try {
await z.number().nonnegative().parseAsync(-1);
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("Number must be greater than or equal to 0");
}
});
test("number nonpositive", async () => {
try {
await z.number().nonpositive().parseAsync(1);
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("Number must be less than or equal to 0");
}
});
test("number negative", async () => {
try {
await z.number().negative().parseAsync(1);
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("Number must be less than 0");
}
});
test("number positive", async () => {
try {
await z.number().positive().parseAsync(-1);
} catch (err) {
expect((err as z.ZodError).issues[0].message).toEqual("Number must be greater than 0");
}
});
test("instantiation", () => {
z.string().min(5);
z.string().max(5);
z.string().length(5);
z.string().email();
z.string().url();
z.string().uuid();
z.string().min(5, { message: "Must be 5 or more characters long" });
z.string().max(5, { message: "Must be 5 or fewer characters long" });
z.string().length(5, { message: "Must be exactly 5 characters long" });
z.string().email({ message: "Invalid email address." });
z.string().url({ message: "Invalid url" });
z.string().uuid({ message: "Invalid UUID" });
});
test("int", async () => {
const int = z.number().int();
int.parse(4);
expect(() => int.parse(3.5)).toThrow();
});