Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/zod/src/v4/classic/tests/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,16 @@ test("index signature in shape", () => {
expectTypeOf<schema>().toEqualTypeOf<Record<string, string>>();
});

test("extent() on object with refinements should throw", () => {
// Updated behavior: `extend` now only throws when trying to overwrite existing keys
// on an object schema that has refinements. Adding new keys is allowed.
test("extend() on object with refinements should not throw when adding new keys", () => {
const schema = z
.object({
a: z.string(),
})
.refine(() => true);

expect(() => schema.extend({ b: z.string() })).toThrow();
expect(() => schema.extend({ b: z.string() })).not.toThrow();
});

test("safeExtend() on object with refinements should not throw", () => {
Expand Down