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
23 lines
591 B
Plaintext
23 lines
591 B
Plaintext
import { expect, test } from "vitest";
|
|
|
|
import * as z from "zod/v4";
|
|
|
|
test(".nullable()", () => {
|
|
const nullable = z.string().nullable();
|
|
expect(nullable.parse(null)).toBe(null);
|
|
expect(nullable.parse("asdf")).toBe("asdf");
|
|
expect(() => nullable.parse(123)).toThrow();
|
|
});
|
|
|
|
test(".nullable unwrap", () => {
|
|
const schema = z.string().nullable();
|
|
expect(schema).toBeInstanceOf(z.ZodNullable);
|
|
expect(schema.unwrap()).toBeInstanceOf(z.ZodString);
|
|
});
|
|
|
|
test("z.null", () => {
|
|
const n = z.null();
|
|
expect(n.parse(null)).toBe(null);
|
|
expect(() => n.parse("asdf")).toThrow();
|
|
});
|