73 lines
2.6 KiB
Plaintext
73 lines
2.6 KiB
Plaintext
import { expect, test } from "vitest";
|
|
import { z } from "../../../../index.js";
|
|
import fr from "../../../locales/fr.js";
|
|
|
|
test("French locale - type name translations in too_small errors", () => {
|
|
z.config(fr());
|
|
|
|
const stringResult = z.string().min(5).safeParse("abc");
|
|
expect(stringResult.success).toBe(false);
|
|
if (!stringResult.success) {
|
|
expect(stringResult.error.issues[0].message).toBe("Trop petit : chaîne doit avoir >=5 caractères");
|
|
}
|
|
|
|
const numberResult = z.number().min(10).safeParse(5);
|
|
expect(numberResult.success).toBe(false);
|
|
if (!numberResult.success) {
|
|
expect(numberResult.error.issues[0].message).toBe("Trop petit : nombre doit être >=10");
|
|
}
|
|
|
|
const arrayResult = z.array(z.string()).min(3).safeParse(["a", "b"]);
|
|
expect(arrayResult.success).toBe(false);
|
|
if (!arrayResult.success) {
|
|
expect(arrayResult.error.issues[0].message).toBe("Trop petit : tableau doit avoir >=3 éléments");
|
|
}
|
|
|
|
const setResult = z
|
|
.set(z.string())
|
|
.min(2)
|
|
.safeParse(new Set(["a"]));
|
|
expect(setResult.success).toBe(false);
|
|
if (!setResult.success) {
|
|
expect(setResult.error.issues[0].message).toBe("Trop petit : ensemble doit avoir >=2 éléments");
|
|
}
|
|
});
|
|
|
|
test("French locale - type name translations in too_big errors", () => {
|
|
z.config(fr());
|
|
|
|
const stringResult = z.string().max(3).safeParse("abcde");
|
|
expect(stringResult.success).toBe(false);
|
|
if (!stringResult.success) {
|
|
expect(stringResult.error.issues[0].message).toBe("Trop grand : chaîne doit avoir <=3 caractères");
|
|
}
|
|
|
|
const numberResult = z.number().max(10).safeParse(15);
|
|
expect(numberResult.success).toBe(false);
|
|
if (!numberResult.success) {
|
|
expect(numberResult.error.issues[0].message).toBe("Trop grand : nombre doit être <=10");
|
|
}
|
|
|
|
const arrayResult = z.array(z.string()).max(2).safeParse(["a", "b", "c"]);
|
|
expect(arrayResult.success).toBe(false);
|
|
if (!arrayResult.success) {
|
|
expect(arrayResult.error.issues[0].message).toBe("Trop grand : tableau doit avoir <=2 éléments");
|
|
}
|
|
});
|
|
|
|
test("French locale - type name translations in invalid_type errors", () => {
|
|
z.config(fr());
|
|
|
|
const stringResult = z.string().safeParse(123);
|
|
expect(stringResult.success).toBe(false);
|
|
if (!stringResult.success) {
|
|
expect(stringResult.error.issues[0].message).toBe("Entrée invalide : chaîne attendu, nombre reçu");
|
|
}
|
|
|
|
const arrayResult = z.array(z.string()).safeParse({});
|
|
expect(arrayResult.success).toBe(false);
|
|
if (!arrayResult.success) {
|
|
expect(arrayResult.error.issues[0].message).toBe("Entrée invalide : tableau attendu, objet reçu");
|
|
}
|
|
});
|