Skip to content

Commit ac8056b

Browse files
committed
Merge branch 'issue-2760-tdd-loose' into issue-2760-final-intersection
2 parents 6a25a3a + 3c6136b commit ac8056b

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

express-zod-api/tests/endpoints-factory.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RequestHandler } from "express";
22
import createHttpError from "http-errors";
3+
import { expectTypeOf } from "vitest";
34
import {
45
EndpointsFactory,
56
Middleware,
@@ -81,6 +82,28 @@ describe("EndpointsFactory", () => {
8182
>
8283
>();
8384
});
85+
86+
test("Issue #2760: should strip excessive props by default", () => {
87+
defaultEndpointsFactory.build({
88+
input: z.object({ foo: z.string() }),
89+
output: z.object({ foo: z.string() }),
90+
handler: async ({ input }) => {
91+
expectTypeOf(input).not.toHaveProperty("bar");
92+
return input;
93+
},
94+
});
95+
});
96+
97+
test("Issue #2760: should allow excessive props when using loose object schema", () => {
98+
defaultEndpointsFactory.build({
99+
input: z.looseObject({ foo: z.string() }),
100+
output: z.object({ foo: z.string() }),
101+
handler: async ({ input }) => {
102+
expectTypeOf(input).toHaveProperty("bar").toEqualTypeOf<unknown>();
103+
return input;
104+
},
105+
});
106+
});
84107
});
85108

86109
describe(".addOptions()", () => {

0 commit comments

Comments
 (0)