Files
klz-cables.com/.pnpm-store/v10/files/a9/01315272c87e6a468df040967794ec6e1af17ed9d87c59b03992a13423531076824ede674be6dc3d07f65d9081f2af80e157b9c33d85f2b247d40fa0e9286a
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

87 lines
2.3 KiB
Plaintext

import { expect, expectTypeOf, test } from "vitest";
import { z } from "zod/v4";
test("nonoptional", () => {
const schema = z.string().nonoptional();
expectTypeOf<typeof schema._input>().toEqualTypeOf<string>();
expectTypeOf<typeof schema._output>().toEqualTypeOf<string>();
const result = schema.safeParse(undefined);
expect(result.success).toBe(false);
expect(result).toMatchInlineSnapshot(`
{
"error": [ZodError: [
{
"expected": "string",
"code": "invalid_type",
"path": [],
"message": "Invalid input: expected string, received undefined"
}
]],
"success": false,
}
`);
});
test("nonoptional with default", () => {
const schema = z.string().optional().nonoptional();
expectTypeOf<typeof schema._input>().toEqualTypeOf<string>();
expectTypeOf<typeof schema._output>().toEqualTypeOf<string>();
const result = schema.safeParse(undefined);
expect(result.success).toBe(false);
expect(result).toMatchInlineSnapshot(`
{
"error": [ZodError: [
{
"code": "invalid_type",
"expected": "nonoptional",
"path": [],
"message": "Invalid input: expected nonoptional, received undefined"
}
]],
"success": false,
}
`);
});
test("nonoptional in object", () => {
const schema = z.object({ hi: z.string().optional().nonoptional() });
expectTypeOf<typeof schema._input>().toEqualTypeOf<{ hi: string }>();
expectTypeOf<typeof schema._output>().toEqualTypeOf<{ hi: string }>();
const r1 = schema.safeParse({ hi: "asdf" });
expect(r1.success).toEqual(true);
const r2 = schema.safeParse({ hi: undefined });
// expect(schema.safeParse({ hi: undefined }).success).toEqual(false);
expect(r2.success).toEqual(false);
expect(r2.error).toMatchInlineSnapshot(`
[ZodError: [
{
"code": "invalid_type",
"expected": "nonoptional",
"path": [
"hi"
],
"message": "Invalid input: expected nonoptional, received undefined"
}
]]
`);
const r3 = schema.safeParse({});
expect(r3.success).toEqual(false);
expect(r3.error).toMatchInlineSnapshot(`
[ZodError: [
{
"code": "invalid_type",
"expected": "nonoptional",
"path": [
"hi"
],
"message": "Invalid input: expected nonoptional, received undefined"
}
]]
`);
});