fix(core-shared): narrow Payload Field union before accessing name in tests
Payload's Field type is a discriminated union; field.name only exists on named variants. Tests now narrow on type (and 'name' in field for groups) before reading variant-specific properties. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,9 @@ import { seoFields } from "./seo-fields";
|
||||
|
||||
describe("seoFields", () => {
|
||||
it("is a group field named 'seo'", () => {
|
||||
if (seoFields.type !== "group" || !("name" in seoFields)) {
|
||||
throw new Error("seoFields must be a named group");
|
||||
}
|
||||
expect(seoFields.name).toBe("seo");
|
||||
expect(seoFields.type).toBe("group");
|
||||
});
|
||||
|
||||
@@ -4,8 +4,8 @@ import { slugField } from "./slug-field";
|
||||
describe("slugField", () => {
|
||||
it("returns a Payload Field with default name 'slug'", () => {
|
||||
const field = slugField();
|
||||
if (field.type !== "text") throw new Error("expected text field");
|
||||
expect(field.name).toBe("slug");
|
||||
expect(field.type).toBe("text");
|
||||
expect(field.required).toBe(true);
|
||||
expect(field.unique).toBe(true);
|
||||
expect(field.index).toBe(true);
|
||||
@@ -13,6 +13,7 @@ describe("slugField", () => {
|
||||
|
||||
it("accepts a custom field name", () => {
|
||||
const field = slugField("permalink");
|
||||
if (field.type !== "text") throw new Error("expected text field");
|
||||
expect(field.name).toBe("permalink");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user